Search code examples
pythonautomationpywinauto

pywinauto does not detect child window


I'm using the latest version (to date) of pywinauto; and also using PyInspect (uia) to identify controls.

I'm automating controls on an application, and part of the process is to check a few boxes on a window that pops up after triggering the window to appear from a menu selection (like Edit->Settings).

The problem is, pywinauto doesn't seem to be able to detect the new window. I see successfully opens; and can see the window and elements as a sub (child?) window of the application in PyInspect.

I've tried wait methods, thinking the automation is occurring too fast- but to no avail. something like:

mysettings = app['app-name'].child_window(title_re="my target settings window", class_name="#32770").wait('exists', timeout=10)

this will just timeout. And if I print control identifiers, "my target settings window" is never included.

app['app-name'].print_control_identifiers()

I also tried set_focus on top_window.. that didn't work either. My conclusion is that pywinauto is having trouble detect that it is there. Any thoughts on this?


Solution

  • I was able to resolve this issue of pywinauto detecting the child window, and the issue that immediately followed: accessing the child window.

    First, I was able to get pywinauto to detect the new window by defining backend='uia' in the application definition, like this:

    app = application.Application(backend='uia')

    I previously just had:

    app = application.Application()

    My next issue was accessing elements on the child window. I could not access the window directly, as I may have anticipated:

    app['my app']['child window']['textbox'].set_edit_text("hello world")

    Instead, this code worked:

    app['my app'].child_window(title='child window name').Edit1.set_edit_text("hello world")

    While I have resolved my issue, I have noticed that after defining backend='uia', the process now executes much slower than before. If anyone who stumbles across this has any feedback in that regard (or optimizing my efforts above), please contribute.

    Thanks