Search code examples
pythonpython-3.xautomationui-automationpywinauto

How to make Pywinauto in Python click a button in a different language?


I just can't get Pywinauto to work. Basically I want it to open the system settings ( figured that out already) and then click "Change Settings" but in my language (German) which would be "Einstellungen ändern". I've tried this:

from pywinauto import Desktop, Application, keyboard 
from pywinauto.application import Application 

app = Application().start("control system") 
#so far it works, after that I've tried two options 
#1  
app.window_(title_re="System").window_(title="Einstellungen ändern").click()
#2
app.window_(best_match="System" ).window_(best_match="Einstellungen ändern").click()

I've tried both of these options with the AutomationId, which I got from Inspect.exe, instead of "System" or "Einstellungen ändern" and I've tried ClickInput() instead of click().

Any ideas?


Solution

  • There are few issues:

    • Correct backend is "uia" that must be specified for Application object.
    • Launcher process spawns a subprocess which requires to reconnect to this child process.

    This code works for my English Win10:

    from pywinauto.application import Application 
    
    app = Application(backend="uia").start("control system")
    app = Application(backend="uia").connect(title="System", timeout=20)
    
    app.window(title="System").child_window(title="Change settings").invoke()
    # app.window(title="System").child_window(title="Einstellungen ändern").invoke()
    

    .click_input() should work as well. Backend "uia" defines method .click() as an alias of .invoke() for control_type="Button" only, because InvokePattern can have different meaning for various control types.


    NOTE: After clicking on "Change settings" the appeared "System properties" window is running inside another process which requires method .connect() again and maybe separate Application instance for your convenience.