Python – Automatically find new window dialog

Automatically find new window dialog… here is a solution to the problem.

Automatically find new window dialog

Let’s say I open some word files with a macro, and the macro opens a dialog box with some buttons.

Is there a way to automatically find these buttons and press them (when there is only PID)?
Currently, I’m using pywinauto to automate GUI testing. It would be great if there was a way to do this with pywinauto.

Thank you.

Solution

Summarize all comments:

You can use the methods .windows() (for the top-level window), immediate .children(), and all .descendants() (the entire subtree as a normal 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'))

Related Problems and Solutions