python自动化安装软件_python模块 - pywinauto(windows自动化安装软件)

GUI 窗口查询工具

spy++lite

pywinauto 模块 原理:

https://www.cnblogs.com/testlife007/p/4710599.html

pywhinayto 常用功能

http://hao.imrrp.com/blog.php?id=4538

点击事件:

https://blog.csdn.net/weixin_40161673/article/details/83246861

捕捉

https://blog.csdn.net/weixin_40161673/article/details/83246861

已摸索实践方法:

自动安装腾讯QQ:(软件默认为win32)

from pywinauto importapplicationimporttime#1.QQ自动安装

app = application.Application().start('D:\software_用户软件\QQ9.0.3.exe')

time.sleep(2)#2.获取 执行程序的窗体#在不知道窗体名称,可以报错的方式查找窗体名称#window_title=['无标题-记事本']#print(app[window_title].wrapper_object())

window_title='腾讯QQ安装向导'

#3.查看一个窗体含有的控件,子窗体,菜单#print(app[window_title].print_control_identifiers())

#4.触发窗体含有的控件,子窗体,菜单#触发方式:app[window_title].child_window(title='窗体名',class_name="窗体类名")

#.click() 点击事件#.set_edit_text() 设置Edit#更多方式可以 通过help(app[window_title].child_window(class_name="Edit"))查到

#点开QQ安装自定义选项

app[window_title].child_window(title="自定义选项").click()

time.sleep(1)#修改默认安装路径

app[window_title].child_window(class_name="Edit").set_edit_text(r'D:\Program Files (x86)\Tencent\QQ')#取消自启动

app[window_title].child_window(title="添加到快速启动栏").click()

app[window_title].child_window(title="开机自动启动").click()#执行安装#print(app[window_title].print_control_identifiers())#help(app[window_title].child_window(class_name="#32770").child_window(title="立即安装", class_name="Button").click())

app[window_title].child_window(class_name="#32770").child_window(title="立即安装", class_name="Button").click()

time.sleep(40)#print(app[window_title].print_control_identifiers())

app[window_title].child_window(class_name="#32770").child_window(title="安装QQ浏览器", class_name="Button").uncheck_by_click()

app[window_title].child_window(class_name="#32770").child_window(title="安装QQ游戏 免费获取专属礼包", class_name="Button").uncheck_by_click()

app[window_title].child_window(class_name="#32770").child_window(title="安装QQ音乐播放器", class_name="Button").uncheck_by_click()

app[window_title].child_window(class_name="#32770").child_window(title="完成安装", class_name="Button").click()

自动安装话务软件:(软件默认为uia)

这个软件自动安装有点特殊,启动的进程不是窗口进程,所有拿不到窗口对象

所以采用connect 进程号的方式去获取 启动的窗口对象.

from pywinauto importapplicationimporttimeimportpsutilimportreimportos

os.popen('D:\software_用户软件\X-Lite电话系统.exe')

time.sleep(1)

PID=0for proc inpsutil.process_iter():try:

pinfo= proc.as_dict(attrs=['pid', 'name'])exceptpsutil.NoSuchProcess:pass

else:if re.match(r'^is.*?.tmp$',pinfo['name']):

PID= pinfo['pid']#print(PID)

app = application.Application(backend='uia').connect(process=PID)#print(app.window(class_name='TWizardForm').print_control_identifiers())#print(dir(app.window(class_name='TWizardForm')))

app.window(class_name='TWizardForm').child_window(title="Next >",control_type="Button").click()#print(app.window(class_name='TWizardForm').print_control_identifiers())

app.window(class_name='TWizardForm').child_window(title="I accept the agreement", control_type="RadioButton").click()

app.window(class_name='TWizardForm').child_window(title="Next >", control_type="Button").click()#print(app.window(class_name='TWizardForm').print_control_identifiers())

app.window(class_name='TWizardForm').child_window(title="To continue, click Next. If you would like t"

"o select a different folder, click Browse.",

control_type="Edit").set_edit_text(r'D:\Program Files (x86)\CounterPath\X-Lite')

app.window(class_name='TWizardForm').child_window(title="Next >",control_type="Button").click()

app.window(class_name='TWizardForm').child_window(title="Next >",control_type="Button").click()

time.sleep(2)#print(app.window(class_name='TWizardForm').print_control_identifiers())#print(dir(app.window(class_name='TWizardForm').child_window(title="Launch X-Lite", control_type="CheckBox")))

app.window(class_name='TWizardForm').child_window(title="Finish", control_type="Button").click()

你可能感兴趣的:(python自动化安装软件)