简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM