Skip to content Skip to sidebar Skip to footer

Pywinauto How Do I Get The List Of Returned Elements

I'm using a WPF application that has custom stack panel, which is basically a list. The item in the list is exactly the same so I'm not able to select a specific text to uniquely i

Solution 1:

You can add found_index=0 or other index to the window specification object. This is the first way to disambiguate the search.

Also there are methods .children() and .descendants() with additional params like control_type or title (as I remember title should work), but some window specification params are not supported in these methods.

Solution 2:

elements = pywinauto.findwindows.find_elements(<args>)
len(elements)

<args> will need to contain more detailed information than it does when using something like Application().connect(process=<pid>).window().child_window(<args>) because it doesn't have information in the chain about the window in which you're searching. See the documentation on this method for more information.

Also note there is a warning that using this method directly is not recommended as it is a low level API.

Another solution (already provided by vasily) is to parse the error that comes back when multiple elements are found to isolate the number found.

Unless the pywinauto devs decide to provide a higher-level API for accessing the number of elements found, you'll have to weigh the risk of the low-level API changing with the risk of parsing an error message which could also change. I have this problem too and have decided to use find_elements()

Post a Comment for "Pywinauto How Do I Get The List Of Returned Elements"