我正在尝试通过正则表达式标题获取另一个 UI 元素的子/后代 UI 元素。
例如,以下代码应该可以工作。
from pywinauto.application import Application, WindowSpecification
root_ws: WindowSpecification = (
Application(backend="uia")
.connect(path="C:/program.exe")
.window(title_re="^Program *")
)
root_ws.descendants(title_re="^abc*", control_type="DataItem")
但是,正如所描述的(Vasily Ryabov)in this comment , title_re 不适用于 child /后代
。
支持通过正则表达式搜索子级的函数是 find_elements
,但它不接受 root_ws
作为父级:
import pywinauto
pywinauto.findwindows.find_elements(title_re="^abc*",
top_level_only=False,
parent=root_ws)
抛出异常AttributeError:'StaticWrapper'对象没有属性'rich_text'
如何仅通过正则表达式标题找到另一个 UI 元素的子元素?
最佳答案
在 pywinauto 0.6.8 中,您可以简单地使用 child_window
来查找元素。它采用与 find_elements
完全相同的参数。
示例:
from pywinauto.application import Application
root_ws = Application(backend="uia").connect(path="C:/program.exe").window(title_re="^Program *")
root_ws.child_window(title_re="^abc*", control_type="DataItem")
关于python - 如何在 pywinauto 中通过正则表达式标题搜索子代/后代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56873733/