How to use the uiautomation.EditControl function in uiautomation

To help you get started, we’ve selected a few uiautomation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_notepad.py View on Github external
auto.ShowDesktop()
    #打开notepad
    subprocess.Popen('notepad')
    #查找notepad, 如果name有中文,python2中要使用Unicode
    window = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad', RegexName = '.* - 记事本')
    #可以判断window是否存在,如果不判断,找不到window的话会抛出异常
    #if window.Exists(maxSearchSeconds = 3):
    if auto.WaitForExist(window, 3):
        auto.Logger.WriteLine("Notepad exists now")
    else:
        auto.Logger.WriteLine("Notepad does not exist after 3 seconds", auto.ConsoleColor.Yellow)
    screenWidth, screenHeight = auto.GetScreenSize()
    window.MoveWindow(screenWidth // 4, screenHeight // 4, screenWidth // 2, screenHeight // 2)
    window.SetActive()
    #查找edit
    edit = auto.EditControl(searchFromControl = window)  #or edit = window.EditControl()
    edit.Click(waitTime = 0)
    #python2中要使用Unicode, 模拟按键
    edit.GetValuePattern().SetValue('hi你好')
    edit.SendKeys('{Ctrl}{End}{Enter}下面开始演示{! 4}{ENTER}', 0.2, 0)
    edit.SendKeys(text)
    edit.SendKeys('{Enter 3}0123456789{Enter}', waitTime = 0)
    edit.SendKeys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{ENTER}', waitTime = 0)
    edit.SendKeys('abcdefghijklmnopqrstuvwxyz{ENTER}', waitTime = 0)
    edit.SendKeys('`~!@#$%^&*()-_=+{ENTER}', waitTime = 0)
    edit.SendKeys('[]{{}{}}\\|;:\'\",<.>/?{ENTER}', waitTime = 0)
    edit.SendKeys('™®①②③④⑤⑥⑦⑧⑨⑩§№☆★○●◎◇◆□℃‰€■△▲※→←↑↓〓¤°#&@\^_―♂♀{ENTER}{CTRL}a')
    window.CaptureToImage('Notepad.png')
    edit.SendKeys('Image Notepad.png was captured, you will see it later.', 0.05)
    #查找菜单
    window.MenuItemControl(Name = '格式(O)').Click()
    window.MenuItemControl(Name = '字体(F)...').Click()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_notepad.py View on Github external
auto.Logger.ColorfullyWriteLine('\nI will open Notepad and automate it. Please wait for a while.')
    time.sleep(2)
    auto.ShowDesktop()
    subprocess.Popen('notepad')
    #search notepad window, if searchFromControl is None, search from RootControl
    #searchDepth = 1 makes searching faster, only searches RootControl's children, not children's children
    window = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad', RegexName = '.* - Notepad')
    #if window.Exists(maxSearchSeconds = 3): #check before using it
    if auto.WaitForExist(window, 3):
        auto.Logger.WriteLine("Notepad exists now")
    else:
        auto.Logger.WriteLine("Notepad does not exist after 3 seconds", auto.ConsoleColor.Yellow)
    screenWidth, screenHeight = auto.GetScreenSize()
    window.MoveWindow(screenWidth // 4, screenHeight // 4, screenWidth // 2, screenHeight // 2)
    window.SetActive()
    edit = auto.EditControl(searchFromControl = window)  #or edit = window.EditControl()
    edit.Click(waitTime = 0)
    edit.GetValuePattern().SetValue('hi你好')
    edit.SendKeys('{Ctrl}{End}{Enter}下面开始演示{! 4}{ENTER}', 0.2, 0)
    edit.SendKeys(text)
    edit.SendKeys('{Enter 3}0123456789{Enter}', waitTime = 0)
    edit.SendKeys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{Enter}', waitTime = 0)
    edit.SendKeys('abcdefghijklmnopqrstuvwxyz{Enter}', waitTime = 0)
    edit.SendKeys('`~!@#$%^&*()-_=+{Enter}', waitTime = 0)
    edit.SendKeys('[]{{}{}}\\|;:\'\",<.>/?{Enter}{Ctrl}a')
    window.CaptureToImage('Notepad.png')
    edit.SendKeys('Image Notepad.png was captured, you will see it later.', 0.05)
    #find menu
    window.MenuItemControl(Name = 'Format').Click()
    window.MenuItemControl(Name = 'Font...').Click()
    windowFont = window.WindowControl(Name = 'Font')
    windowFont.ComboBoxControl(AutomationId = '1140').Select('Western')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
find = True
                        break
                    y -= 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            if find:
                break
            else:
                automation.SendKeys('{Esc}')
                time.sleep(0.5)
        if not find:
            automation.Logger.Log('this pdf not support editing')
            exit(0)
        menuItem.Click(simulateMove = False, waitTime = 0.2)
        edit = automation.EditControl(searchFromControl= tree, searchDepth= 1)
        edit.SetValue(newName, waitTime = 0.05)
        automation.SendKeys('{Enter}', waitTime = 0.05)
        automation.Logger.Write('rename: ')
        automation.Logger.WriteLine(name, automation.ConsoleColor.Green)
        automation.Logger.Write('    @@to : ' if alert else '    to: ')
        automation.Logger.WriteLine(newName, automation.ConsoleColor.Yellow if alert else automation.ConsoleColor.Green)
    if depth + 1 > TreeDepth:
        return
    if automation.ExpandCollapseState.Collapsed == treeItem.CurrentExpandCollapseState():
        treeItem.Expand(0.1)
    childItems = treeItem.GetChildren()
    if childItems:
        for child in childItems:
            RenameTreeItem(tree, child, bookMark.children, depth + 1, removeChapter)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / notepadtop.py View on Github external
isTop = 1
    print(sys.argv)

    if len(sys.argv) == 2:
        isTop = int(sys.argv[1])

    note = automation.WindowControl(searchDepth=1, ClassName='Notepad')
    if note.Exists(0, 0):
        note.SetTopmost(isTop)
    else:
        subprocess.Popen('notepad')
        note.Refind()
        note.SetTopmost(isTop)
        note.Move(0, 0)
        note.Resize(400, 300)
        edit = automation.EditControl(searchFromControl=note)
        edit.Click()
        automation.SendKeys('I\'m a topmost window!!!')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_firefox.py View on Github external
searchEdit = firefoxWindow.Control(Compare = lambda c, d:
        (isinstance(c, automation.EditControl) or isinstance(c, automation.ComboBoxControl)) and c.Name == 'Enter your search term')
    searchEdit.Click()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / get_qq_group_members.py View on Github external
def GetPersonDetail():
    detailWindow = automation.WindowControl(searchDepth= 1, ClassName = 'TXGuiFoundation', SubName = '的资料')
    details = ''
    for control, depth in automation.WalkControl(detailWindow):
        if isinstance(control, automation.EditControl):
            details += control.Name + control.CurrentValue() + '\n'
    details += '\n' * 2
    detailWindow.Click(-10, 10)
    return details