记录并自动化winform和wpf应用程序
autogui的Python项目详细描述
#自动图形用户界面
autogui是一个gui自动化/测试工具,为用户提供高级关键字,以自动化wpf和winform应用程序。
##入门 使用pip安装
pip安装autogui
我建议在“工具”文件夹或“我的recorderspy repo”中使用类似recorderspy.exe的间谍工具。使用ctrl-r开始录制,ctrl-e结束录制,ctrl-w在录制期间选择gui元素。这将生成步骤的python和robot脚本。
任何其他的windows spy工具,比如microsofts inspect.exe工具,都将有助于找到元素的定位器属性。
大多数情况下,您可以只使用默认选择器(名称)来查找元素。
###实例 打开计算器,单击几个按钮并关闭。 ` from autogui import * open("calc")click("One")click("Two") close() ` 打开记事本,读写一些文字,然后关闭。 ` from autogui import * open("notepad")write("My name is Alex Lundberg","Text Editor") click("value:=My name is Alex Lundberg") sendkey("{ENTER}") append(" and this AutoGui","Text Editor") print(read("TextEditor")) close() `
打开记事本和计算器,并使用setwindow()在它们之间移动。 ` from autogui import * open("calc")print(getActiveWindow())open("notepad")print(getActiveWindow())setWindow("calculator")print(getActiveWindow())click("One",0,4) #clicks on the first element(0) that matches title = "One". Changes timeout to 4 seconds #with selectors other than title you will need to use := with the property value to match click("One,controltype:=button,id:=num1Button,class=Button")close("Untitled - Notepad") close() #closes calculator window `
###方法 ` click(id,child=0,timeout=timeout) write(value,id,child=0,timeout=timeout) setWindow(id,contains=True,timeout=timeout) append(value,id,child=0,timeout=timeout) rightclick(id,child=0,timeout=timeout) sendkey(key) read(id,child=0,timeout=timeout) open(app,setActive=True) close(window="activeWindow") getActiveWindow() `
###选择器 若要选择元素,请尝试使用以下任一方法: ` name id value class controltype ` 属性以以下格式馈送到函数的id输入中:prop1:=propvalue,prop2:=prop2value。不需要在title属性前面加上前缀。 [可用属性的完整列表](https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationElement)
##许可证
这个项目是根据麻省理工学院的许可证授权的