- Win32 API
- Accessibility
def enum(hwnd, extra):When we know the application handle, we can enumerate its children:
global app_handle
if winxpgui.GetWindowText(hwnd).find('GUIAT - Proof') >= 0:
app_handle = hwnd
app_handle = None
winxpgui.EnumWindows(enum, '')
print 'Test application handle:', app_handle
def enum_child(hwnd, extra):When you run the whole script (source), you get:
print '%s %s: %s' % (hwnd, winxpgui.GetClassName(hwnd),
winxpgui.GetWindowText(hwnd))
winxpgui.EnumChildWindows(app_handle, enum_child, '')
Test application handle: 2949744Here is the catch. How shall we identify Add Item button from Quit button? Both have the same class name WindowsForms10.BUTTON.app.0.378734a. Sure, the text differs, but this isn't always true. Imagine two text boxes - both having the same class name WindowsForms10.EDIT.app.0.378734a. What then? Of course, you can check positions. But this is leads you back to record/play tools and that is exactly what I want to avoid.
2621886 WindowsForms10.BUTTON.app.0.378734a: Add Item
7668314 WindowsForms10.STATIC.app.0.378734a: New listbox item
4194952 WindowsForms10.EDIT.app.0.378734a:
2753142 WindowsForms10.LISTBOX.app.0.378734a:
3342924 WindowsForms10.BUTTON.app.0.378734a: Quit
So this is the terminus for Win32 API. Next time - Accessibility.
3 comments:
What version of Python was this done with? I noticed the 'prints' don't play nice with 3.2.2 and I'm worried other parts (that are less easy to fix) won't work...
Any help appreciated!
This was Python 2.x but it should not be a big problem to port it to Python 3.x - just try it and you will see.
This is a great post thanks for writing it
Post a Comment