technomalogical
technomalogical

Reputation: 3002

Using Windows UI Automation via CPython/pywin32?

Based on a question I read and responded to on Reddit, I've been investigating using the relatively new Windows UI Automation framework via Python (and pywin32) to query custom widgets inside a Google Chrome window. UISpy shows me the control I'm interested in, but the naming conventions and lack of window classes make me believe the UI Automation framework is the only way to access it. I was able to get as far as generating a COM stub for the UI Automation library via PythonWin and the Makepy utility, but couldn't actually instantiate the COM object. I don't have a lot of experience with COM, outside of following along in Mark Hammond's "Python Programming on Win32" to drive Excel via COM with Python. I found an article describing how to instantiate the COM object from C/C++ but I wasn't able to get much from it.

I think I can follow along with the API documentation if I can just figure out how to instantiate the object.

Upvotes: 4

Views: 2167

Answers (2)

Bill Agee
Bill Agee

Reputation: 3656

You can use the awesome comtypes package to easily use the IUIAutomation COM interface from CPython scripts.

Here's a very simple demo I wrote:

https://github.com/billagee/test-polyglot/blob/master/printDesktopUiaElementName/ms-ui-automation-com-api/python/comtypes/print_desktop_uia_element_name.py

Upvotes: 3

Eric Brown
Eric Brown

Reputation: 13942

Try win32com.client.gencache, particularly GetModuleForCLSID(["e22ad333-b25f-460c-83d0-0581107395c9") - the clsid for the Win32 implementation of IUIAutomation.

Upvotes: 1

Related Questions