python~windows自动化工具 uiautomation库
2022/7/12 5:20:14
本文主要是介绍python~windows自动化工具 uiautomation库,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
微软提供了关于自动化操作PC端桌面应用程序的工具,官方描述为:
Microsoft UI Automation is an accessibility framework that enables Windows applications to provide and consume programmatic information about user interfaces (UIs). It provides programmatic access to most UI elements on the desktop. It enables assistive technology products, such as screen readers, to provide information about the UI to end users and to manipulate the UI by means other than standard input. UI Automation also allows automated test scripts to interact with the UI.
Python库为我们封装了shoppingmode 微软UI Automation的API,即uiautomation库。
资料
微软官网关于UI Automation的介绍:
1、IUIAutomationElement interface:
https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationelement
2、Control Types and Their Supported Control Patterns,查看全部的Control-Pattern支持表格。
https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-controlpatternmapping
3、uiautomation库的具体用法,GitHub上开发者发布的教程:
https://github.com/yinkaisheng/Python-UIAutomation-for-Windows/blob/master/readme_cn.md
安装automation
1、安装uiautomation库
# pip install uiautomation
python中默认的安装目录为: C:\Users\XXX\AppData\Local\Programs\Python\Python310\Scripts
2、使用
https://blog.csdn.net/freeking101/article/details/105758387
automation.py -h 查看帮忙
automation.py -t 0, 打印当前激活窗口的所有控件
automation.py -r -d 1 -t 0, 打印桌面(树的根控件 )和它的第一层子窗口(TopLevel顶层窗口)
进入windwos PowerShell,到automation.py的目录;
通过命令: python automation.py +参数:
1)、查看帮助
PS C:\Users\gXXX\AppData\Local\Programs\Python\Python310\Scripts> python automation.py -h UIAutomation 2.0.16 (Python 3.10.5, 64 bit) usage -h show command help -t delay time, default 3 seconds, begin to enumerate after Value seconds, this must be an integer you can delay a few seconds and make a window active so automation can enumerate the active window -d enumerate tree depth, this must be an integer, if it is null, enumerate the whole tree -r enumerate from root:Desktop window, if it is null, enumerate from foreground window -f enumerate from focused control, if it is null, enumerate from foreground window -c enumerate the control under cursor, if depth is < 0, enumerate from its ancestor up to depth -a show ancestors of the control under cursor -n show control full name, if it is null, show first 30 characters of control's name in console, always show full name in log file @AutomationLog.txt -p show process id of controls
2)、抓取微信控件
-a,表述抓取所有
-t3,表示延迟3s抓取;
此处执行命令后,将鼠标移至微信,抓取信息如下:
PS C:\Users\gXX\AppData\Local\Programs\Python\Python310\Scripts> python automation.py -a -t3 UIAutomation 2.0.16 (Python 3.10.5, 64 bit) please wait for 3 seconds 2022-07-11 08:21:51.523 automation.py[79] main -> Starts, Current Cursor Position: (195, 354) ControlType: PaneControl ClassName: #32769 AutomationId: Rect: (0,0,1920,1080)[1920x1080] Name: 'Desktop 1' Handle: 0x10010(65552) Depth: 0 SupportedPattern: LegacyIAccessiblePattern ControlType: WindowControl ClassName: WeChatMainWndForPC AutomationId: Rect: (12,151,1150,951)[1138x800] Name: 'WeChat' Handle: 0x90568(591208) Depth: 1 SupportedPattern: LegacyIAccessiblePattern ScrollItemPattern TransformPattern WindowPattern 2022-07-11 08:21:51.951 automation.py[114] main -> Ends PS C:\Users\goXXX\AppData\Local\Programs\Python\Python310\Scripts>
# 定义程序窗口
iautomation.WindowControl(Name='WeChat')
# 切到到程序窗口
iautomation.WindowControl(Name='WeChat').SwitchToThisWindow()
这篇关于python~windows自动化工具 uiautomation库的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门