简介
由于UIAutomation的官方文档只有一个github中的readme文件,只是简单的使用示例,具体使用还需要在代码中查找,非常不方便。经过我多年使用UIAutomation开发的经验和整理,把常用的功能梳理成本文档,作为我的开发参考使用,这样就不用每次都翻代码了,同时也可以使用AI编程时作为参考文档使用
UIAutomation是一个用于Windows UI自动化的Python库,可以用来实现Windows桌面应用程序的自动化控制。它基于Windows UI Automation API,提供了丰富的界面控件操作功能。
主要功能
1. 控件查找
# 获取根控件
root = auto.GetRootControl()# 获取焦点控件
focused = auto.GetFocusedControl() # 获取前台控件
foreground = auto.GetForegroundControl()# 通过坐标获取控件
control = auto.ControlFromPoint(x, y)# 通过窗口句柄获取控件
control = auto.ControlFromHandle(hwnd)# 获取父控件
parent = control.GetParentControl()# 获取第一个子控件
firstChild = control.GetFirstChildControl()# 获取最后一个子控件
lastChild = control.GetLastChildControl()# 获取下一个兄弟控件
nextSibling = control.GetNextSiblingControl()# 获取上一个兄弟控件
prevSibling = control.GetPreviousSiblingControl()# 获取所有子控件
children = control.GetChildren()# 获取祖先控件
ancestor = control.GetAncestorControl(condition)
2. 控件基本操作
# 检查控件是否存在
control.Exists(maxSearchSeconds=5)# 等待控件消失
control.Disappears(maxSearchSeconds=5)# 重新查找控件
control.Refind(maxSearchSeconds=5)# 获取控件位置
rect = control.BoundingRectangle