pythonGUI自动化:uiautomation的常见使用

一、在web系统GUI自动化测试中,可以用uiautomation进行辅助

二、程序窗口:WindowControl()

  按钮:ButtonControl()

  文件显示:TextControl()

  输入框:EditControl()

三、一般定位的属性有:ClassName、Name、ProcessId、AutomationId

四、实现代码如下:

import os
import subprocess
import uiautomation
import time
#打开计算器进程
subprocess.Popen(calc.exe)
time.sleep(2)
#定位窗口
wc=uiautomation.WindowControl(searchDepth=1,Name=计算器)
#设置为顶层
wc.SetTopmost(True)
wc.ButtonControl(Name=7).Click()
wc.ButtonControl(Name=).Click()
wc.ButtonControl(Name=5).Click()
wc.ButtonControl(Name=等于).Click()
result=wc.TextControl(AutomationId=158)
print(result.Name)
if result.Name=="12":
    print("测试成功")
else:
    print("测试失败")
#截图
wc.CaptureToImage(1.png)
time.sleep(2)
wc.ButtonControl(Name=关闭).Click()
os.system("taskkill /F /IM calc.exe")

 

import uiautomation
import time
uiautomation.RightClick(1405,361)
uiautomation.Click(1468,37)
wc=uiautomation.WindowControl(searchDepth=1,Name=yx)
wc.SetTopmost(True)
edit=uiautomation.EditControl(ProcessId=764(QQ))
for i in range(10):
    edit.Click()
    edit.SendKeys(在干嘛啊)
    wc.ButtonControl(Name=发送(&S)).Click()
    time.sleep(3)
文章来自:https://www.cnblogs.com/badbadboyyx/p/12150114.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3