How to use the uiautomation.WindowControl 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_help_demo.py View on Github external
def DemoEN():
    """for other language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite('I will run cmd\n\n')
    time.sleep(3)

    auto.SendKeys('{Win}r')
    while not isinstance(auto.GetFocusedControl(), auto.EditControl):
        time.sleep(1)
    auto.SendKeys('cmd{Enter}')
    cmdWindow = auto.WindowControl(SubName = 'cmd.exe')
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 10)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('I will run Notepad and type Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
time.sleep(3)

    auto.SendKeys('{Win}r')
    while not isinstance(auto.GetFocusedControl(), auto.EditControl):
        time.sleep(1)
    auto.SendKeys('cmd{Enter}')
    cmdWindow = auto.WindowControl(SubName = 'cmd.exe')
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 10)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('I will run Notepad and type Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -h" to display the help\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -h'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_notepad.py View on Github external
def testNotepadEN():
    consoleWindow = auto.GetConsoleWindow()
    consoleWindow.SetActive()
    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)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_calculator.py View on Github external
'5' : 'num5Button',
        '6' : 'num6Button',
        '7' : 'num7Button',
        '8' : 'num8Button',
        '9' : 'num9Button',
        '.' : 'decimalSeparatorButton',
        '+' : 'plusButton',
        '-' : 'minusButton',
        '*' : 'multiplyButton',
        '/' : 'divideButton',
        '=' : 'equalButton',
        '(' : 'openParanthesisButton',
        ')' : 'closeParanthesisButton',
    }
    #Desc is not a valid search property, but it can be used for debug printing
    calcWindow = auto.WindowControl(searchDepth = 1, ClassName = 'ApplicationFrameWindow', Name = 'Calculator', Desc='Calculator Window')
    if not calcWindow.Exists(0, 0):
        subprocess.Popen('calc')
    calcWindow.SetActive()
    calcWindow.ButtonControl(AutomationId = 'NavButton').Click()
    calcWindow.ListItemControl(Name = 'Scientific Calculator').Click()
    calcWindow.ButtonControl(AutomationId='clearButton').Click()
    if 1:
        char2Button = {key: calcWindow.ButtonControl(AutomationId=char2Id[key], Desc='Button ' + key) for key in char2Id}
    else:
        #Run faster because it only walk calc window once
        id2char = {v: k for k, v in char2Id.items()}
        char2Button = {}
        for c, d in auto.WalkControl(calcWindow, maxDepth=3):
            if c.AutomationId in id2char:
                char2Button[id2char[c.AutomationId]] = c
    Calc(calcWindow, char2Button, '1234 * (4 + 5 + 6) - 78 / 90.8')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_calculator.py View on Github external
def CalcOnXP():
    chars = '0123456789.+-*/=()'
    #Desc is not a valid search property, but it can be used for debug printing
    calcWindow = auto.WindowControl(searchDepth=1, ClassName='SciCalc', Desc='Calculator Window')
    if not calcWindow.Exists(0, 0):
        subprocess.Popen('calc')
    calcWindow.SetActive()
    calcWindow.SendKeys('{Alt}vs', 0.5)
    clearBtn = calcWindow.ButtonControl(Name = 'CE')  #
    clearBtn.Click()
    if 0:
        char2Button = {key: calcWindow.ButtonControl(Name=key, Desc='Button ' + key) for key in chars}
    else:
        #Run faster because it only walk calc window once
        char2Button = {}
        for c, d in auto.WalkControl(calcWindow, maxDepth=1):
            if c.Name in chars:
                char2Button[c.Name] = c
    Calc(calcWindow, char2Button, '1234 * (4 + 5 + 6) - 78 / 90.8')
    Calc(calcWindow, char2Button, '3*3+4*4')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_firefox.py View on Github external
def main():
    firefoxWindow = automation.WindowControl(searchDepth = 1, ClassName = 'MozillaWindowClass')
    if not firefoxWindow.Exists(0):
        automation.Logger.WriteLine('please run Firefox first', automation.ConsoleColor.Yellow)
        return
    firefoxWindow.ShowWindow(automation.ShowWindow.Maximize)
    firefoxWindow.SetActive()
    time.sleep(1)
    tab = firefoxWindow.TabControl()
    newTabButton = tab.ButtonControl(searchDepth= 1)
    newTabButton.Click()
    edit = firefoxWindow.EditControl()
    # edit.Click()
    edit.SendKeys('https://www.bing.com/?rb=0&setmkt=en-us&setlang=en-us{Enter}')
    time.sleep(2)
    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
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
def BatchRename():
    foxitWindow = automation.WindowControl(searchDepth= 1, ClassName= 'classFoxitReader')
    foxitWindow.ShowWindow(automation.ShowWindow.ShowMaximized)
    ret = foxitWindow.SetActive()
    print('SetActive', ret)
    automation.Logger.Log(foxitWindow.Name[:-len(' - Foxit Reader')] + '\n')
    automation.SendKeys('{Ctrl}0')
    for aid in ['59583', '60682', '60683']:
        editToolBar = automation.ToolBarControl(searchFromControl= foxitWindow, AutomationId = aid, Name = 'Caption Bar')
        if editToolBar.Exists(0, 0):
            editToolBar.Click(-40, 0.5)
            automation.SendKeys('{Alt}y')
    paneWindow = automation.WindowControl(searchFromControl= foxitWindow, AutomationId = '65280')
    bookmarkPane = automation.PaneControl(searchFromControl= paneWindow, searchDepth= 1, foundIndex= 1)
    l, t, r, b = bookmarkPane.BoundingRectangle
    #bookmarkButton = automation.ButtonControl(searchFromControl= bookmarkPane, Name = '书签') # can't find, but automation -a can find it, why
    if bookmarkPane.Name == '书签':
        if r - l < 40:
            bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
            if bookmarkButton.Name == '书签':
                bookmarkButton.Click(simulateMove= False)
    else:
        bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
        if bookmarkButton.Name == '书签':
            bookmarkButton.Click(simulateMove= False)
    tree = automation.TreeControl(searchFromControl= foxitWindow, ClassName= 'SysTreeView32')
    childItems = tree.GetChildren()
    bookMarks = []
    depth = 1