Search code examples
ui-automationpywinauto

After launching app, it takes 30+ seconds before able to access elements through pywinauto


I'm testing a custom WPF application using pywinauto.

When connecting with win32, I don't get any dependents, so I'm connecting with uia.

After I launch the application, I can immediately connect with pywinauto, but it takes 30s+ before I'm able to access any elements. After the initial delay, interacting and searching for controls is quick.

I call windows() as a way to wait until the application lets me interact with it.

main_app = Application(backend="uia").connect(path=APP_PATH)
main_app.windows()

On investigation, the hanging seems to occur during: "application.py" > "windows" > "findwindows.find_elements(...)" > "element.children(...).

If I open the application, and wait for 1 minute, and then run the script, then it occurs almost immediately. And finding subsequent controls is quick.

I appear to see this same behaviour when using inspect.exe to view the hierarchy. If I refresh immediately after opening the application, it takes 30s+ to show anything. But If I wait a minute before refreshing, it updates immediately.

I was wondering if someone else had experienced this before, and what might be the cause/solution.

I am running: Windows 10, python 3.8.3, pywinauto 0.6.8


Solution

  • After debugging some more, I have resolved the issue, although it's not clear to me what the root cause actually was.

    The custom application I'm testing launches a background application as a non-visible console. Testing showed that not running this background application allowed me to conenct immediately. Running the background application by itself would cause the same delay in inspect.exe loading.

    The application was a dotnet framework application, that in theory was a console only application, but had code supporting a WPF interface (which was not displayed). By removing the WPF aspects of the project, I was able to build the application as a purely console application, and I no longer experienced the earlier delays.