Python pywinauto 自动操作Windows GUI
原创
©著作权归作者所有:来自51CTO博客作者小龙在山东的原创作品,请联系作者获取转载授权,否则将追究法律责任
简介
pywinauto依赖pywin32,可以自动操作微软windows窗口、鼠标、键盘。
优势:面向对象,简单
安装
例子
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