1

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?

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
ETVator
  • 43
  • 2
  • 7
  • Default backend is `"win32"` which relies to Spy++. If you're using `Inspect.exe`, use `Application(backend="uia")` then. – Vasily Ryabov Jan 04 '19 at 17:25

1 Answers1

1

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.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thank you so much, it finally works now :) is there an easy way to figure out when a sub/child process is spawned, so i know when i have to reconnect? – ETVator Jan 04 '19 at 19:04
  • Inspect.exe shows process ID for every element/window. For example, Win10 Calculator has few processes for one window. Yeah, even such crazy things are possible. We have plans to implement spawned child process detection for next major release. – Vasily Ryabov Jan 05 '19 at 05:50