views:

88

answers:

1

I have a GUI application which can create many similar windows on desktop. All windows have same title. I have to enumerate all dialogs with same title and make some tests against each of such dialogs.

If I call:

dialog = app['Window Name']

pywinauto returns a WindowSpecification object which is useful along with accessing controls by name.

When I call:

dialogs = app.windows_(title='Window Name')

pywinauto returns me a list of HwndWrapper instances which are not so useful.

How to obtain a list of windows with specified title but as WindowSpecification objects?

+1  A: 

Hi, You can't really. WindowSpecification is a single specification for all windows that match the criteria supplied. When you work with a WindowSpecification instance you are often interacting with an HwndWrapper instance that WindowSpecification is finding and accessing for you.

So I think the answer is to work with the HwndWrapper's returned by app.windows_() (similar to the single HwndWrapper returned by WindowSpecification.WrapperObject()

Note - if you are always trying to narrow down the list of windows by looking at particular controls within a window - then using app['Window Name']['Unique Control Name'].Parent() should return the window.

The main difference between WindowSpecification and HwndWrapper is that a WindowSpecification does not have to exist yet, while a HwndWrapper instance reflects a particular underlying windows handle. This allows WindowSpecification to implement code that waits for windows or checks if they exist.

markm
With HwndWrapper I cant access controls as dictionary items like dialog['window']['control']Is there a way to jump from HwndWrapper to WindowSpecification?My windows are all the same so I cant search-and-jump to parent :(
Denis Barmenkov
Yes - you can. ws = WindowSpecification({'handle': hwnd_wrapper_instance.handle)This will create a WindowSpecification that matches only one dialog/control (which has that particular handle).
markm