-
Notifications
You must be signed in to change notification settings - Fork 675
Old wiki FAQ
Application.start_("c:\app command line.exe")
Application.connect_(path = "c:\app command line.exe")
or
Application.connect_(handle = your_window_hwnd_as_int)
or
# any of the other options for pywinauto.findwindows.find_windows()
# can be used too
Application.connect_(title = "Untitled - Notepad", class = "Notepad")
or
Application.connect_(process = your_process_id_as_int)
- Create an application instance Application()
- start_() a new or connect_() to an existing application
- The easiest way is now to use attribute access
myapp.DialogTitle
or (item access)
myapp['Dialog Title']
or (top window)
myapp.top_window_()
or
# any of the other options for pywinauto.findwindows.find_windows()
# can be used too (error raised if more then one window or no window
# found that matches the criteria)
myapp.window_(class = "Notepad", title_re = ".*Notepad")
or
# any of the other options for pywinauto.findwindows.find_windows()
# can be used too (this one will not raise any errors and will return
# all the windows that match the criteria.
# Criteria are optional - specifying no criteria will return a list
# of all windows for this process.
myapp.windows_(class = "Notepad")
More or less the same as for Dialogs except you need to get dialog reference first, and top_window_() and windows_() methods do not apply. e.g.
myapp.mydlg.MyControl
myapp.mydlg['MyControl']
myapp.window_(title = 'My control', class = "Button")
Various names are associated with each control in a dialog, and when specifying a control reference using either attribute myapp.dlg.ctrl
or item access myapp.dlg['ctrl']
will perform a lookup for the control that has a name that best mathes the requested attribute or item.
The algorithm used is:
- One name is the Text of the control (if the text is not empty)
- One name is the FriendlyClass of the control
- One name is the Text + FriendlyClass of the control (if text is not empty)
- If text is empty then we find the closest text control above and/or to the left (hopefully but not necessarily the static label associated with the control) and add a name that has ClosestText + FriendlyClass
So a control may have 2-3 different names! You can call print_control_identifiers on a dialog (or on a control) specification to request the available names (note these names will not have been disambiguated - see next step!) myapp.mydlg.print_control_indentifiers()
Now some of these names may conflict with other controls (e.g. if you have 5 buttons then each of them has at least one name "Button").
So the next step is to disambiguate the list of names to ensure that no names are duplicated. So the first button in the above example will have the following names:
- text
- text + "Button"
- "Button"
- "Button0"
- "Button1"
These last two allow 1 based indexing of the controls the next control will get "Button2" etc.