Search code examples
pythonpython-2.7pywinauto

PyWinAuto opening applications, but not returning any window dialogs


I am attempting to write a script to automate the setup of a new development machine. I have been using PyWinAuto to try to automate the installation of various programs which mostly use WinForm (or similar) GUI windows.

PyWinAuto opens the application properly, but does not return any windows. I have installed SWAPY and it shows me controls that I expect to see, but they do not work in the code. I tried using PyWinAuto 0.6.3 as well as 0.5.4 with Python 2.7.13 and 2.7.12 respectively (I am on a Windows 7 32-bit machine) and nothing has worked.

Here are examples of errors I am getting:

    import pywinauto
    from pywinauto.application import Application

    app = Application()
    app.Start("C:\setup.exe")
    appSetup = app.Setup
    appSetup.Wait('ready')
    ...
    ...
    Error: pywinauto.timings.TimeoutError: timed out

or

    app = Application()
    app.Start("C:\setup.exe")
    appSetup = app.Setup
    appSetup.ClickInput()
    ...
    ...
    Error: pywinauto.findbestmatch.MatchError: Could not find 'Setup' in '[]'

Here is an example of one installation that I am getting errors on: Boost Install Window with SWAPY Description

Your help is much appreciated. Thank you!


Solution

  • This problem occurs when the application you are targeting spawns a new process after starting. To fix this problem (with help from @VasilyRyabov - thank you!), I start the application as I did before (app.start("C:\setup.exe") and then connect the application (app.connect(title="Setup")) so you are connected to the process that is running the GUI window.

    In some cases I have had to add a delay between these two functions if it does not spawn the second process fast enough. This issue posted on GitHub is very similar to this scenario.