How to use uiautomation - 10 common examples

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_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
    auto.SendKeys('{Home}', waitTime=0.1)
    columnCount = 0
    treeItemCount = 0
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
    auto.SendKeys('{Home}', waitTime=0.1)
    columnCount = 0
    treeItemCount = 0
    for item, depth in auto.WalkControl(tree):
        if isinstance(item, auto.HeaderControl):
            columnCount += 1
            auto.Logger.Write(item.Name + ' ')
        elif isinstance(item, auto.TreeItemControl):
            if treeItemCount % columnCount == 0:
                auto.Logger.Write('\n')
                time.sleep(0.1)
            treeItemCount += 1
            auto.Logger.Write(item.Name + ' ')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
    auto.SendKeys('{Home}', waitTime=0.1)
    columnCount = 0
    treeItemCount = 0
    for item, depth in auto.WalkControl(tree):
        if isinstance(item, auto.HeaderControl):
            columnCount += 1
            auto.Logger.Write(item.Name + ' ')
        elif isinstance(item, auto.TreeItemControl):
            if treeItemCount % columnCount == 0:
                auto.Logger.Write('\n')
                time.sleep(0.1)
            treeItemCount += 1
            auto.Logger.Write(item.Name + ' ')
            if item.BoundingRectangle.bottom >= rect.bottom:
                auto.SendKeys('{PageDown}', waitTime=0.1)
        if auto.IsKeyPressed(auto.Keys.VK_F1):
            auto.Logger.WriteLine('\nF1 pressed', auto.ConsoleColor.Yellow)
            break
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
    auto.SendKeys('{Home}', waitTime=0.1)
    columnCount = 0
    treeItemCount = 0
    for item, depth in auto.WalkControl(tree):
        if isinstance(item, auto.HeaderControl):
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
p.__dict__, diffTimeStamp, p.Time-lastTime, sumTime, sumTimeFromTimeStamp, sumTimeFromTimeStamp - sumTime))
        lastTime = p.Time
        lastTimeStamp = p.TimeStamp
    if frameCount:
        averageDiff = totalDiff // frameCount
        frameCount += 1
        seqCount = packets[-1].Seq - packets[0].Seq + 1
        totalTimeFromTimeStamp = (framePackets[-1].TimeStamp - framePackets[0].TimeStamp) / sampleRate
        realTime = framePackets[-1].Time - framePackets[0].Time
        automation.Logger.ColorfulWriteLine('\n接收包总数: {0}, 帧数: {1}, 实际帧率:{2:.2f}, 平均时间戳: {3}, 接收总时间: {4:.6f}, 时间戳总时间: {5:.6f}, 丢包率: {6}/{7}({8:.2f}%)'.format(
            len(packets), frameCount, frameCount / realTime, averageDiff, realTime, totalTimeFromTimeStamp, len(lostSeqs), seqCount, len(lostSeqs) / seqCount * 100))
        automation.Logger.ColorfulWriteLine('第一个包Seq: {}, TimeStamp: {}, 最后一个包Seq: {}, TimeStamp: {}, 包总数: {}, 丢包数: {}\n'.format(
            packets[0].Seq, packets[0].TimeStamp, packets[-1].Seq, packets[-1].TimeStamp, seqCount, len(lostSeqs)))
        if showLost:
            lostStr = ''.join([('\n' + str(it) + ',') if i % 20 == 0 else (str(it) + ',') for i, it in enumerate(lostSeqs)])
            automation.Logger.WriteLine('丢包序号:\n{}'.format(lostStr))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
cmdTransformPattern.Resize(sw // 2, sh * 3 // 4)
    subprocess.Popen('mmc.exe devmgmt.msc')
    mmcWindow = auto.WindowControl(searchDepth = 1, ClassName = 'MMCMainFrame')
    mmcTransformPattern = mmcWindow.GetTransformPattern()
    mmcTransformPattern.Move(0, 0)
    mmcTransformPattern.Resize(sw // 2, sh * 3 // 4)
    tree = mmcWindow.TreeControl()
    for item, depth in auto.WalkControl(tree, includeTop=True):
        if isinstance(item, auto.TreeItemControl):  #or item.ControlType == auto.ControlType.TreeItemControl
            item.GetSelectionItemPattern().Select(waitTime=0.05)
            pattern = item.GetExpandCollapsePattern()
            if pattern.ExpandCollapseState == auto.ExpandCollapseState.Collapsed:
                pattern.Expand(waitTime=0.05)
            auto.Logger.WriteLine(' ' * (depth - 1) * 4 + item.Name, auto.ConsoleColor.Green)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll by SetScrollPercent')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime=1)
    treeScrollPattern = tree.GetScrollPattern()
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 0)
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 100)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to top by SendKeys Ctrl+Home')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime = 1)
    tree.SendKeys('{Ctrl}{Home}', waitTime = 1)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to bottom by SendKeys Ctrl+End')
        cmdWindow.SetActive(waitTime = 1)
    mmcWindow.SetActive(waitTime = 1)
    tree.SendKeys('{Ctrl}{End}', waitTime = 1)
    if cmdWindow:
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)
    edit.SendKeys('`~!@#$%^&*()-_=+{Enter}', waitTime = 0)
    edit.SendKeys('[]{{}{}}\\|;:\'\",<.>/?{Enter}{Ctrl}a')
    window.CaptureToImage('Notepad.png')
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__)