Waiting for Long Operations¶
A GUI application behaviour is often unstable and your script needs waiting until a new window appears or an existing window is closed/hidden. pywinauto can wait for a dialog initialization implicitly (with the default timeout). There are few methods/functions that could help you to make your code easier and more reliable.
Application methods¶
- WaitCPUUsageLower (new in pywinauto 0.5.2)
This method is useful for multi-threaded interfaces that allow a lazy initialization in another thread while GUI is responsive and all controls already exist and ready to use. So waiting for a specific window existence/state is useless. In such case the CPU usage for the whole process indicates that a task calculation is not finished yet.
Example:
app.WaitCPUUsageLower(threshold=5) # wait until CPU usage is lower than 5%
WindowSpecification methods¶
These methods are available to all controls.
There is an example containing long waits: install script for 7zip 9.20 x64.
A WindowSpecification
object isn’t necessarily related to an existing window/control.
It’s just a description namely a couple of criteria to search the window. The Wait
method (if no any exception is raised)
can guarantee that the target control exists or even visible, enabled and/or active.