Using Windows UI Automation via CPython / pywin32?

Based on a question that I read and answered on Reddit, I studied using the relatively new Windows UI Automation framework through Python (and pywin32) to request custom widgets inside a Google Chrome window. UISpy shows me a control that interests me, but the naming conventions and the lack of window classes make me think that the user interface infrastructure is the only way to access it. I was able to modify the COM stub for the user interface automation library through PythonWin and the Makepy utility, but could not create an instance of the COM object. I don’t have much experience with COM, beyond Mark Hammond’s next “Python Programming in Win32” for managing Excel through COM with Python. I found an articledescribing how to instantiate a COM object from C / C ++ , but I couldn’t get much from it.

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

+4
source share
2 answers

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

Here is a very simple demo that I wrote:

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

+3
source

All Articles