def inspect_element( cls, action: str = "Click", control_window: bool = True, recording: Optional[List["RecordElement"]] = None, verbose: bool = False, ) -> List[str]: """Inspect Windows element under mouse pointer. :param action: Action attached to the locator. :param control_window: Include relevant ``Control Window ...`` statement or not. :param recording: Where to store records. :param verbose: Show exhaustive locators if `True`, otherwise just simple ones. """ # TODO: Python syntax support too instead of just RF. output = [] with auto.UIAutomationInitializerInThread(debug=False): control = auto.ControlFromCursor() parent_control = control.GetParentControl() try: top_level_control = control.GetTopLevelControl() except AttributeError: top_level_control = None top_level_name = top_level_handle = "N/A" else: top_level_name = top_level_control.Name top_level_handle = top_level_control.NativeWindowHandle parent_locator = ( cls._get_element_key_properties(parent_control, verbose=verbose) or "N/A" ) child_locator = ( cls._get_element_key_properties(control, verbose=verbose) or "N/A" ) locator_path = f"{parent_locator} > {child_locator}" if "name:" in child_locator or "id:" in child_locator: locator_path = child_locator if control_window: output.append(f"Control Window {top_level_name}") if action: output.append(f"{action} {locator_path}") else: output.append(locator_path) if recording is not None: recording.append( { "type": "locator", "top": top_level_name, "top_handle": top_level_handle, "x": top_level_control, "locator": locator_path, "name": parent_control.Name if parent_control else None, "control": parent_control, } ) return output
def main(): treeItem = automation.ControlFromCursor() if isinstance(treeItem, automation.TreeItemControl) or isinstance(treeItem, automation.TreeControl): while ExpandFromRoot: if isinstance(treeItem, automation.TreeControl): break treeItem = treeItem.GetParentControl() ExpandTreeItem(treeItem) else: automation.Logger.WriteLine('the control under cursor is not a tree control', automation.ConsoleColor.Yellow)
def main(): tree = auto.ControlFromCursor() if ExpandFromRoot: tree = tree.GetAncestorControl( lambda c, d: isinstance(c, auto.TreeControl)) if isinstance(tree, auto.TreeItemControl) or isinstance( tree, auto.TreeControl): ExpandTreeItem(tree) else: auto.Logger.WriteLine('the control under cursor is not a tree control', auto.ConsoleColor.Yellow)
def main(args): if args.time > 0: time.sleep(args.time) start = time.clock() if args.active: c = automation.GetForegroundControl() elif args.cursor or args.up: c = automation.ControlFromCursor() elif args.fullscreen: c = automation.GetRootControl() CaptureControl(c, args.path, args.up) automation.Logger.WriteLine('cost time: {:.3f} s'.format(time.clock() - start))
def main(): automation.Logger.WriteLine('请把鼠标放在QQ群聊天窗口中的一个成员上面,3秒后获取\n') time.sleep(3) listItem = automation.ControlFromCursor() if listItem.ControlType != automation.ControlType.ListItemControl: automation.Logger.WriteLine('没有放在群成员上面,程序退出!') return consoleWindow = automation.GetConsoleWindow() consoleWindow.SetActive() qqWindow = listItem.GetTopWindow() list = listItem.GetParentControl() allListItems = list.GetChildren() f=open(r'f:\resqq.txt','a') for listItem in allListItems: automation.Logger.WriteLine(listItem.Name) f.write(listItem.Name) f.close()
def main(): automation.Logger.WriteLine('请把鼠标放在QQ群聊天窗口中的一个成员上面,3秒后获取\n') time.sleep(3) listItem = automation.ControlFromCursor() if listItem.ControlType != automation.ControlType.ListItemControl: automation.Logger.WriteLine('没有放在群成员上面,程序退出!') return consoleWindow = automation.GetConsoleWindow() if consoleWindow: consoleWindow.SetActive() qqWindow = listItem.GetTopWindow() list = listItem.GetParentControl() allListItems = list.GetChildren() for listItem in allListItems: automation.Logger.WriteLine(listItem.Name) answer = 'y' if answer.lower() == 'y': automation.Logger.WriteLine('\n3秒后开始获取QQ群成员详细资料,您可以一直按住F10键暂停脚本') time.sleep(3) qqWindow.SetActive() #确保群里第一个成员可见在最上面 left, top, right, bottom = list.BoundingRectangle while allListItems[0].BoundingRectangle[1] < top: automation.Win32API.MouseClick(right - 5, top + 20) for listItem in allListItems: if listItem.ControlType == automation.ControlType.ListItemControl: if automation.Win32API.IsKeyPressed(automation.Keys.VK_F10): if consoleWindow: consoleWindow.SetActive() input('\n您暂停了脚本,按Enter继续\n') qqWindow.SetActive() listItem.RightClick() menu = automation.MenuControl(searchDepth= 1, ClassName = 'TXGuiFoundation') menuItems = menu.GetChildren() for menuItem in menuItems: if menuItem.Name == '查看资料': menuItem.Click() break automation.Logger.WriteLine('eachpersonstart') automation.Logger.WriteLine(listItem.Name, automation.ConsoleColor.Green) automation.Logger.WriteLine(GetPersonDetail()) listItem.Click() automation.SendKeys('{Down}')
def main(args): if args.time > 0: time.sleep(args.time) start = time.time() if args.active: c = auto.GetForegroundControl() CaptureControl(c, args.path, args.up) elif args.cursor or args.up: c = auto.ControlFromCursor() CaptureControl(c, args.path, args.up) elif args.fullscreen: c = auto.GetRootControl() rects = auto.GetMonitorsRect() dot = args.path.rfind('.') for i, rect in enumerate(rects): path = args.path[:dot] + '_' * i + args.path[dot:] c.CaptureToImage(path, rect.left, rect.top, rect.width(), rect.height()) auto.Logger.WriteLine('capture image: ' + path) auto.Logger.WriteLine('cost time: {:.3f} s'.format(time.time() - start))
def main(): formats = auto.GetClipboardFormats() for k, v in formats.items(): auto.Logger.WriteLineColorfully( 'Clipboard has format <Color=Cyan>{}, {}</Color>'.format(k, v)) if k == auto.ClipboardFormat.CF_UNICODETEXT: auto.Logger.WriteLineColorfully( ' Text in clipboard is: <Color=Cyan>{}</Color>'.format( auto.GetClipboardText())) elif k == auto.ClipboardFormat.CF_HTML: htmlText = auto.GetClipboardHtml() auto.Logger.WriteLineColorfully( ' Html text in clipboard is: <Color=Cyan>{}</Color>'.format( htmlText)) elif k == auto.ClipboardFormat.CF_BITMAP: auto.Logger.WriteLineColorfully( ' Bitmap clipboard is: <Color=Cyan>{}</Color>'.format( auto.GetClipboardBitmap())) auto.InputColorfully( 'paused, press Enter to test <Color=Cyan>SetClipboardText</Color>', auto.ConsoleColor.Green) auto.SetClipboardText('Hello World') auto.InputColorfully( '<Color=Yellow>You can paste it in Office Word now.</Color>\npaused, press Enter to test <Color=Cyan>SetClipboardHtml</Color>' ) auto.SetClipboardHtml( '<h1>Title</h1><br><h3>Hello</h3><br><p>test html</p><br>'), auto.InputColorfully( '<Color=Yellow>You can paste it in Office Word now.</Color>\npaused, press Enter to test <Color=Cyan>SetClipboardBitmap</Color>' ) c = auto.ControlFromCursor() with c.ToBitmap() as bmp: auto.SetClipboardBitmap(bmp) auto.InputColorfully( '<Color=Yellow>You can paste it in Office Word now.</Color>\npaused, press Enter to <Color=Cyan>exit</Color>' )
def main(): import getopt auto.Logger.Write('UIAutomation {} (Python {}.{}.{}, {} bit)\n'.format( auto.VERSION, sys.version_info.major, sys.version_info.minor, sys.version_info.micro, 64 if sys.maxsize > 0xFFFFFFFF else 32)) options, args = getopt.getopt(sys.argv[1:], 'hrfcand:t:', [ 'help', 'root', 'focus', 'cursor', 'ancestor', 'showAllName', 'depth=', 'time=' ]) root = False focus = False cursor = False ancestor = False foreground = True showAllName = False depth = 0xFFFFFFFF seconds = 3 for (o, v) in options: if o in ('-h', '-help'): usage() exit(0) elif o in ('-r', '-root'): root = True foreground = False elif o in ('-f', '-focus'): focus = True foreground = False elif o in ('-c', '-cursor'): cursor = True foreground = False elif o in ('-a', '-ancestor'): ancestor = True foreground = False elif o in ('-n', '-showAllName'): showAllName = True elif o in ('-d', '-depth'): depth = int(v) elif o in ('-t', '-time'): seconds = int(v) if seconds > 0: auto.Logger.Write('please wait for {0} seconds\n\n'.format(seconds), writeToFile=False) time.sleep(seconds) auto.Logger.Log('Starts, Current Cursor Position: {}'.format( auto.GetCursorPos())) control = None if root: control = auto.GetRootControl() if focus: control = auto.GetFocusedControl() if cursor: control = auto.ControlFromCursor() if depth < 0: while depth < 0 and control: control = control.GetParentControl() depth += 1 depth = 0xFFFFFFFF if ancestor: control = auto.ControlFromCursor() if control: auto.EnumAndLogControlAncestors(control, showAllName) else: auto.Logger.Write( 'IUIAutomation returns null element under cursor\n', auto.ConsoleColor.Yellow) else: indent = 0 if not control: control = auto.GetFocusedControl() controlList = [] while control: controlList.insert(0, control) control = control.GetParentControl() if len(controlList) == 1: control = controlList[0] else: control = controlList[1] if foreground: indent = 1 auto.LogControl(controlList[0], 0, showAllName) auto.EnumAndLogControl(control, depth, showAllName, startDepth=indent) auto.Logger.Log('Ends\n')
def capture(stopEvent: Event): with auto.UIAutomationInitializerInThread(debug=True): control = auto.ControlFromCursor() control.CaptureToImage('control.png') subprocess.Popen('control.png', shell=True)
def main(): treeItem = automation.ControlFromCursor() CollapseTreeItem(treeItem)
import uiautomation # import ruamel.yaml as yaml import time time.sleep(5) elemnt = uiautomation.ControlFromCursor() print(elemnt) # # f = open("testcase.yaml") # rs = yaml.safe_load(f) # f.close() # print(rs['TestSet']) # testitems=rs['TestSet'] # # for i in dict(testitems).keys(): # if testitems[i] == "PASS" or testitems[i] == 'FAIL': # continue # if i == "test4": # testitems[i] = "FAIL" # else: # testitems[i] = "PASS" # with open('testcase.yaml','w+') as f1: # yaml.dump(rs,f1, default_flow_style=False,allow_unicode=True)
def main(): auto.Logger.WriteLine('请把鼠标放在QQ群聊天窗口中右下角群成员列表中的一个成员上面,3秒后获取\n', auto.ConsoleColor.Cyan, writeToFile=False) time.sleep(3) listItem = auto.ControlFromCursor() if listItem.ControlType != auto.ControlType.ListItemControl: auto.Logger.WriteLine('没有放在群成员上面,程序退出!', auto.ConsoleColor.Cyan, writeToFile=False) return consoleWindow = auto.GetConsoleWindow() if consoleWindow: consoleWindow.SetActive() qqWindow = listItem.GetTopLevelControl() list = listItem.GetParentControl() allListItems = list.GetChildren() for li in allListItems: auto.Logger.WriteLine(li.Name) pass auto.Logger.WriteLine('是否获取成员详细信息?按F9继续,F10退出', auto.ConsoleColor.Cyan, writeToFile=False) while True: if auto.IsKeyPressed(auto.Keys.VK_F9): break elif auto.IsKeyPressed(auto.Keys.VK_F10): return time.sleep(0.05) auto.Logger.WriteLine('\n3秒后开始获取QQ群成员详细资料,您可以一直按住F10键暂停脚本', auto.ConsoleColor.Cyan, writeToFile=False) time.sleep(3) qqWindow.SetActive() #确保群里第一个成员可见在最上面 list.Click() list.SendKeys('{Home}', waitTime=1) for listItem in allListItems: if listItem.ControlType == auto.ControlType.ListItemControl: if auto.IsKeyPressed(auto.Keys.VK_F10): if consoleWindow: consoleWindow.SetActive() auto.Logger.WriteLine('\n您暂停了脚本,按F9继续\n', auto.ConsoleColor.Cyan, writeToFile=False) while True: if auto.IsKeyPressed(auto.Keys.VK_F9): break time.sleep(0.05) qqWindow.SetActive() listItem.RightClick(waitTime=2) menu = auto.MenuControl(searchDepth=1, ClassName='TXGuiFoundation') menuItems = menu.GetChildren() for menuItem in menuItems: if menuItem.Name == '查看资料': menuItem.Click(40) break auto.Logger.WriteLine(listItem.Name, auto.ConsoleColor.Green) auto.Logger.WriteLine(GetPersonDetail()) listItem.Click() auto.SendKeys('{Down}')