4

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.

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

This seems like it's on the right track, but there are a couple problems with your code. First, there's an open bracket for a list on the left side and none on the right. I tried without it and with a closing bracket and the function returned None. Next, I didn't specify, but I'm on Windows 7. This CLSID is for the Windows 8 version. I looked in the docs and found the CLSID for the older version, but when I tried the same statement I still got None back from the function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.