| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

FAQ

Page history last edited by PBworks 18 years ago

How do I start an application?

Application.start_("c:\app command line.exe")

 

How do I connect to an application?

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)

 

 

How do I get a reference to a window?

1) Create an application instance Application()

2) start_() a new or connect_() to an existing application

3) 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")

 

How do I get a reference to a control?

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")

 

How do I figure out what can be used to reference a control?

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.

 

So how do you know what names have been associated with a control?

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.

Comments (0)

You don't have permission to comment on this page.