版权声明:本文为博主原创文章,欢迎转载,转载时请以超链接形式标明文章原始出处。 https://blog.csdn.net/lilongsy/article/details/81607793
简介
pywinauto依赖pywin32,可以自动操作微软windows窗口、鼠标、键盘。
优势:面向对象,简单
安装
pip install -U pywinauto
例子
app.UntitledNotepad.menu_select("File->SaveAs")
app.SaveAs.ComboBox5.select("UTF-8")
app.SaveAs.edit1.set_text("Example-utf8.txt")
app.SaveAs.Save.click()
from pywinauto import Desktop, Application
Application().start('explorer.exe "C:\\Program Files"')
# connect to another process spawned by explorer.exe
# Note: make sure the script is running as Administrator!
app = Application(backend="uia").connect(path="explorer.exe", title="Program Files")
app.ProgramFiles.set_focus()
common_files = app.ProgramFiles.ItemsView.get_item('Common Files')
common_files.right_click_input()
app.ContextMenu.Properties.invoke()
# this dialog is open in another process (Desktop object doesn't rely on any process id)
Properties = Desktop(backend='uia').Common_Files_Properties
Properties.print_control_identifiers()
Properties.Cancel.click()
Properties.wait_not('visible') # make sure the dialog is closed
类似工具
PyAutoGui 跨平台,无依赖,但是没有基于文本的控件操作。
Lackey 基于图像模式匹配
AXUI 另一个MS UI的封装API
winGuiAuto Win32 API的模块
pyahk按键精灵
pyautoit依赖autoit.dll实现autoit的各种自动化功能
参考
https://pywinauto.readthedocs.io/en/latest/contents.html
https://github.com/pywinauto/pywinauto
https://www.cnblogs.com/gayhub/p/5861032.html