How to use the uiautomation.Logger.ColorfullyWriteLine 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_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_notepad.py View on Github external
def testNotepadCN():
    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()
    #打开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
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)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / hide_window_with_hotkey.py View on Github external
import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--main', action='store_true', help='exec main')
    parser.add_argument('--hide', action='store_true', help='hide window')
    parser.add_argument('--show', action='store_true', help='show window')
    args = parser.parse_args()

    if args.main:
        if args.hide:
            hide()
        elif args.show:
            show()
    else:
        subprocess.Popen('notepad')
        auto.GetConsoleWindow().SetActive()
        auto.Logger.ColorfullyWriteLine('Press Ctr+1 to hide\nPress Ctr+2 to show\n')
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): lambda e: HotKeyFunc(e, ['--main', '--hide']),
                            (auto.ModifierKey.Control, auto.Keys.VK_2): lambda e: HotKeyFunc(e, ['--main', '--show']),
                          },
                           (auto.ModifierKey.Control, auto.Keys.VK_9))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
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:
        auto.Logger.ColorfullyWriteLine('Scroll to top by WheelUp')
        cmdWindow.SetActive(waitTime = 1)
    print(tree.NativeWindowHandle, tree.Element, len(tree.GetChildren()))
    # before expand, tree has no scrollbar. after expand, tree has a scrollbar.
    # need to Refind on some PCs before find ScrollBarControl from tree
    # maybe the old element has no scrollbar info
    tree.Refind()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
else:
            break
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to bottom by WheelDown')
        cmdWindow.SetActive(waitTime = 1)
    while True:
        vPercent = treeScrollPattern.VerticalScrollPercent
        vPercent2 = rangeValuePattern.Value
        print('ScrollPattern.VerticalScrollPercent', vPercent)
        print('ValuePattern.Value', vPercent2)
        if vPercent2 < 100:
            tree.WheelDown(waitTime = 0.05)
        else:
            break
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll by DragDrop')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime = 1)
    x, y = thumb.MoveCursorToMyCenter()
    auto.DragDrop(x, y, x, vScrollBarRect.top, waitTime=1)
    x, y = thumb.MoveCursorToMyCenter()
    auto.DragDrop(x, y, x, vScrollBarRect.bottom)
    mmcWindow.GetWindowPattern().Close()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
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:
        auto.Logger.ColorfullyWriteLine('Scroll to top by WheelUp')
        cmdWindow.SetActive(waitTime = 1)
    print(tree.NativeWindowHandle, tree.Element, len(tree.GetChildren()))
    # before expand, tree has no scrollbar. after expand, tree has a scrollbar.
    # need to Refind on some PCs before find ScrollBarControl from tree
    # maybe the old element has no scrollbar info
    tree.Refind()
    print(tree.NativeWindowHandle, tree.Element, len(tree.GetChildren()))
    vScrollBar = tree.ScrollBarControl(AutomationId='NonClientVerticalScrollBar')
    rangeValuePattern = vScrollBar.GetRangeValuePattern()
    vScrollBarRect = vScrollBar.BoundingRectangle
    thumb = vScrollBar.ThumbControl()
    while True:
        vPercent = treeScrollPattern.VerticalScrollPercent
        vPercent2 = rangeValuePattern.Value
        print('ScrollPattern.VerticalScrollPercent', vPercent)
        print('ValuePattern.Value', vPercent2)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
print(tree.NativeWindowHandle, tree.Element, len(tree.GetChildren()))
    vScrollBar = tree.ScrollBarControl(AutomationId='NonClientVerticalScrollBar')
    rangeValuePattern = vScrollBar.GetRangeValuePattern()
    vScrollBarRect = vScrollBar.BoundingRectangle
    thumb = vScrollBar.ThumbControl()
    while True:
        vPercent = treeScrollPattern.VerticalScrollPercent
        vPercent2 = rangeValuePattern.Value
        print('ScrollPattern.VerticalScrollPercent', vPercent)
        print('ValuePattern.Value', vPercent2)
        if vPercent2 > 0:
            tree.WheelUp(waitTime=0.05)
        else:
            break
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to bottom by WheelDown')
        cmdWindow.SetActive(waitTime = 1)
    while True:
        vPercent = treeScrollPattern.VerticalScrollPercent
        vPercent2 = rangeValuePattern.Value
        print('ScrollPattern.VerticalScrollPercent', vPercent)
        print('ValuePattern.Value', vPercent2)
        if vPercent2 < 100:
            tree.WheelDown(waitTime = 0.05)
        else:
            break
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll by DragDrop')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime = 1)
    x, y = thumb.MoveCursorToMyCenter()
    auto.DragDrop(x, y, x, vScrollBarRect.top, waitTime=1)