我正在尝试通过正则表达式标题获取另一个 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")
然而,正如所描述的(通过瓦西里·里亚博夫 https://stackoverflow.com/users/3648361/vasily-ryabov) 在这个评论中 https://stackoverflow.com/questions/46432544/pywinauto-how-do-i-get-the-list-of-returned-elements#comment86088573_49458557, 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'
如何仅通过正则表达式标题找到另一个 UI 元素的子元素?