Search code examples
pythonwindowspywinautogui-testing

Find new window dialogs automatically


Let's say that I open up some word file with a macro that opens up a dialog with some buttons.

Is there a way to find those buttons automatically and press them (when having only the PID)?
Currently, I'm using pywinauto to automate the GUI testing. If there's a way to do it with pywinauto that would be great.

Thanks.


Solution

  • To summarize all the comments:

    It's possible to enumerate all the windows and their controls using methods .windows() (for top-level windows), immediate .children() and all the .descendants() (the whole subtree as a plain list). You can even filter children and descendants by class_name, control_type, content_only and/or title.

    Example:

    print(app.windows()[0].descendants(control_type='Edit'))