我试图通过RegexP标题来获取另一个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所述(在此评论中,title_re is not possible for children/descendants
。
支持正则表达式搜索儿童的功能是find_elements
,但是它不接受root_ws
作为父:
import pywinauto
pywinauto.findwindows.find_elements(title_re="^abc*",
top_level_only=False,
parent=root_ws)
抛出异常AttributeError: 'StaticWrapper' object has no attribute 'rich_text'
我如何只有一个RegexP标题来找到另一个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")