2

I am trying to get children/descendant UI elements of another UI element by a regexp title.

For example, the following code should work.

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")

However, as described (by Vasily Ryabov) in this comment, title_re is not possible for children/descendants.

The function that supports search of children by a regular expression is find_elements, however it doesn't accept root_ws as parent:

import pywinauto
pywinauto.findwindows.find_elements(title_re="^abc*", 
                                    top_level_only=False,
                                    parent=root_ws)

throws an exception AttributeError: 'StaticWrapper' object has no attribute 'rich_text'

How could I find a child of another UI element by only having a regexp title?

Elijas Dapšauskas
  • 909
  • 10
  • 25
  • 1
    Can you provide full traceback of the exception? Also the code is not equivalent, because you missed param `backend="uia"` for `find_elements`. It is passed by higher level object to `find_elements` automatically. – Vasily Ryabov Jul 04 '19 at 09:13

1 Answers1

1

In pywinauto 0.6.8, you can simply use child_window to find an element. It takes the same exact parameters as find_elements.

Example:

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")
CrazyVideoGamer
  • 754
  • 8
  • 22