Reformat the code sections (make them indented)
This commit is contained in:
parent
16557200bf
commit
22a934de48
@ -6,17 +6,22 @@ How to sepcify an usable Application instance
|
||||
---------------------------------------------
|
||||
An ``Application()`` instance is the point of contact for all work
|
||||
with the app you are automating. So the Application instance needs
|
||||
to be connected to a process. There are two ways of doing this::
|
||||
to be connected to a process. There are two ways of doing this:
|
||||
|
||||
::
|
||||
|
||||
start_(self, cmd_line, timeout = app_start_timeout):
|
||||
|
||||
or ::
|
||||
or:
|
||||
|
||||
::
|
||||
|
||||
connect_(self, **kwargs):
|
||||
|
||||
|
||||
``start_()`` is used when the application is not running and you
|
||||
need to start it. Use it in the following way::
|
||||
need to start it. Use it in the following way:
|
||||
|
||||
::
|
||||
|
||||
app = Application()
|
||||
app.start_(r"c:\path\to\your\application -a -n -y --arguments")
|
||||
@ -30,7 +35,7 @@ one of the following:
|
||||
|
||||
:process: the process id of the application, e.g.
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
app = Application()
|
||||
app.connect_(process = 2341)
|
||||
@ -38,7 +43,7 @@ one of the following:
|
||||
|
||||
:handle: The windows handle of a window of the application, e.g.
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
app = Application()
|
||||
app.connect_(handle = 0x010f0c)
|
||||
@ -48,13 +53,16 @@ one of the following:
|
||||
is used to find the path of each process and compared against
|
||||
the value passed in) e.g.
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
app = Application()
|
||||
app.connect_(path = r"c:\windows\system32\notepad.exe")
|
||||
|
||||
|
||||
or any combination of the parameters that specify a window, these get
|
||||
passed to the ``findwindows.find_windows()`` function. e.g. ::
|
||||
passed to the ``findwindows.find_windows()`` function. e.g.
|
||||
|
||||
::
|
||||
|
||||
app = Application()
|
||||
app.connect_(title_re = ".*Notepad", class_name = "Notepad")
|
||||
@ -77,16 +85,21 @@ Once the application instance knows what application it is connected to
|
||||
a dialog to work on needs to be specified.
|
||||
|
||||
There are many different ways of doing this. The most common will be
|
||||
using item or attribute access to select a dialog based on it's title. e.g ::
|
||||
using item or attribute access to select a dialog based on it's title. e.g
|
||||
|
||||
::
|
||||
|
||||
dlg = app.Notepad
|
||||
|
||||
or equivalently ::
|
||||
or equivalently
|
||||
|
||||
::
|
||||
|
||||
dlg = app['Notepad']
|
||||
|
||||
The next easiest method is to ask for the ``top_window_()`` e.g.
|
||||
|
||||
The next easiest method is to ask for the ``top_window_()`` e.g. ::
|
||||
::
|
||||
|
||||
dlg = app.top_window_()
|
||||
|
||||
@ -98,23 +111,31 @@ return the correct window. It will definitely be a top level window of
|
||||
the application - it just might not be the one highest in the Z-Order.
|
||||
|
||||
If this is not enough control they you can use the same parameters as
|
||||
can be passed to ``findwindows.find_windows()`` e.g. ::
|
||||
can be passed to ``findwindows.find_windows()`` e.g.
|
||||
|
||||
::
|
||||
|
||||
dlg = app.window_(title_re = "Page Setup", class_name = "#32770")
|
||||
|
||||
Finally to have the most control you can use ::
|
||||
Finally to have the most control you can use
|
||||
|
||||
::
|
||||
|
||||
dialogs = app.windows_()
|
||||
|
||||
this will return a list of all the visible, enabled, top level windows
|
||||
of the application. You can then use some of the methods in ``handleprops``
|
||||
module select the dialog you want. Once you have the handle you need
|
||||
then use ::
|
||||
then use
|
||||
|
||||
::
|
||||
|
||||
Application.window_(handle = win)
|
||||
|
||||
**Note**: If the title of the dialog is very long - then attribute access
|
||||
might be very long to type, in those cases it is usually easier to use::
|
||||
might be very long to type, in those cases it is usually easier to use
|
||||
|
||||
::
|
||||
|
||||
app.window_(title_re = ".*Part of Title.*")
|
||||
|
||||
@ -123,7 +144,9 @@ might be very long to type, in those cases it is usually easier to use::
|
||||
How to specify a control on a dialog
|
||||
------------------------------------
|
||||
|
||||
There are a number of ways to specify a control, the simplest are::
|
||||
There are a number of ways to specify a control, the simplest are
|
||||
|
||||
::
|
||||
|
||||
app.dlg.control
|
||||
app['dlg']['control']
|
||||
@ -134,27 +157,29 @@ strings e.g. app[u'your dlg title'][u'your ctrl title']
|
||||
|
||||
The code builds up multiple identifiers for each control from the following:
|
||||
|
||||
+ title
|
||||
+ friendly class
|
||||
+ title + friendly class
|
||||
- title
|
||||
- friendly class
|
||||
- title + friendly class
|
||||
|
||||
If the control's text is empty (after removing non char characters) text is
|
||||
not used. Instead we look for the closest control above and to the right fo
|
||||
the contol. And append the friendly class. So the list becomes
|
||||
|
||||
+ friendly class
|
||||
+ closest text + friendly class
|
||||
- friendly class
|
||||
- closest text + friendly class
|
||||
|
||||
Once a set of identifiers has been created for all controls in the dialog
|
||||
we disambiguate them.
|
||||
|
||||
use the `WindowSpecification.print_control_identifiers()` method
|
||||
|
||||
e.g. ::
|
||||
e.g.
|
||||
::
|
||||
|
||||
app.YourDialog.print_control_identifiers()
|
||||
|
||||
Sample output::
|
||||
Sample output
|
||||
::
|
||||
|
||||
Button - Paper (L1075, T394, R1411, B485)
|
||||
'PaperGroupBox' 'Paper' 'GroupBox'
|
||||
@ -222,7 +247,9 @@ the first one can be refered to as "Edit", "Edit0", "Edit1" and the 2nd
|
||||
should be refered to as "Edit2"
|
||||
|
||||
**Note** You do not have to be exact!. Say we take an instance from the
|
||||
example above::
|
||||
example above
|
||||
|
||||
::
|
||||
|
||||
Button - Margins (inches) (L1183, T493, R1411, B584)
|
||||
'Marginsinches' 'MarginsinchesGroupBox' 'GroupBox'
|
||||
@ -237,7 +264,9 @@ Well you CAN! The code does a best match on the identifer you use against
|
||||
all the available identifiers in the dialog.
|
||||
|
||||
For example if you break into the debugger you can see how different
|
||||
identifiers can be used::
|
||||
identifiers can be used
|
||||
|
||||
::
|
||||
|
||||
(Pdb) print app.PageSetup.Margins.Text()
|
||||
Margins (inches)
|
||||
@ -257,15 +286,21 @@ you cannot use attribute access to reference a control so
|
||||
you would either have to use item access or make an explicit
|
||||
calls to ``window_()``.
|
||||
|
||||
So instead of writing::
|
||||
So instead of writing
|
||||
|
||||
::
|
||||
|
||||
app.dialog_ident.control_ident.Click()
|
||||
|
||||
You would have to write::
|
||||
You would have to write
|
||||
|
||||
::
|
||||
|
||||
app['dialog_ident']['control_ident'].Click()
|
||||
|
||||
Or use ``window_()`` explictly::
|
||||
Or use ``window_()`` explictly
|
||||
|
||||
::
|
||||
|
||||
app.window_(title_re = "NonAsciiCharacters").window_(title = "MoreNonAsciiCharacters").Click()
|
||||
|
||||
@ -283,7 +318,9 @@ that the developer has told Windows that they will override how items are displa
|
||||
and do it themselves. And in this case they have made it so that strings cannot be
|
||||
retrieved :-(.
|
||||
|
||||
So what problems does this cause? ::
|
||||
So what problems does this cause?
|
||||
|
||||
::
|
||||
|
||||
app.HelpTopics.ListBox.Texts() # 1
|
||||
app.HelpTopics.ListBox.Select("ItemInList") # 2
|
||||
@ -295,7 +332,9 @@ So what problems does this cause? ::
|
||||
2. This will fail with an IndexError because the Select(string) method of a ListBox
|
||||
looks for the item in the Texts to know the index of the item that it should select.
|
||||
|
||||
The following workaround will work on this control ::
|
||||
The following workaround will work on this control
|
||||
|
||||
::
|
||||
|
||||
app.HelpTopics.ListBox.Select(1)
|
||||
|
||||
@ -307,7 +346,9 @@ control does not respond to standard events like Select. In this case the only w
|
||||
you can select items in the listbox is by using the keyboard simulation of TypeKeys().
|
||||
|
||||
This allows you to send any keystrokes to a control. So to select the 3rd item you
|
||||
would use::
|
||||
would use
|
||||
|
||||
::
|
||||
|
||||
app.Helptopics.ListBox1.TypeKeys("{HOME}{DOWN 2}{ENTER}")
|
||||
|
||||
@ -320,7 +361,9 @@ If your application made extensive use of a similar control type then you could
|
||||
make using it easier by deriving a new class from ListBox, that could use extra
|
||||
knowledge about your particular application. For example in the WinHelp example
|
||||
evertime an item is highlighted in the list view, it's text is inserted into the
|
||||
Edit control above the list, and you CAN get the text of the item from there e.g. ::
|
||||
Edit control above the list, and you CAN get the text of the item from there e.g.
|
||||
|
||||
::
|
||||
|
||||
# print the text of the item currently selected in the list box
|
||||
# (as long as you are not typing into the Edit control!)
|
||||
@ -341,7 +384,9 @@ The things that are important to remember is that you are looking for a
|
||||
window in the "Explorer.exe" application with the class "Shell_TrayWnd" that has
|
||||
a Toolbar control with a title "Notification Area".
|
||||
|
||||
One way to get this is to do the following::
|
||||
One way to get this is to do the following
|
||||
|
||||
::
|
||||
|
||||
imprt pywinauto.application
|
||||
app = pywinauto.application.Application().connect_(path = "explorer")
|
||||
@ -351,30 +396,21 @@ The taskbar module provides very preliminary access to the System Tray.
|
||||
|
||||
It defines the following variables:
|
||||
|
||||
:``explorer_app``: defines an Application() object connected to the running
|
||||
:explorer_app: defines an Application() object connected to the running
|
||||
explorer. You probably don't need to use this your self
|
||||
very much.
|
||||
|
||||
:``TaskBar``: The handle to the task bar (the bar containing Start Button,
|
||||
:TaskBar: The handle to the task bar (the bar containing Start Button,
|
||||
the QuickLaunch icons, running tasks, etc
|
||||
|
||||
:``StartButton``: "Start me up" :-) I think you might know what this is!
|
||||
|
||||
:``QuickLaunch``: The Toolbar with the quick launch icons
|
||||
|
||||
:``SystemTray``: The window that contains the Clock and System Tray Icons
|
||||
|
||||
:``Clock``: The clock
|
||||
|
||||
:``SystemTrayIcons``: The toolbar representing the system tray icons
|
||||
|
||||
:``RunningApplications``: The toolbar representing the running applications
|
||||
|
||||
:StartButton: "Start me up" :-) I think you might know what this is!
|
||||
:QuickLaunch: The Toolbar with the quick launch icons
|
||||
:SystemTray: The window that contains the Clock and System Tray Icons
|
||||
:Clock: The clock
|
||||
:SystemTrayIcons: The toolbar representing the system tray icons
|
||||
:RunningApplications: The toolbar representing the running applications
|
||||
|
||||
I have also provided 2 functions in the module that can be used to click on
|
||||
system tray icons:
|
||||
|
||||
|
||||
:``ClickSystemTrayIcon(button)``: You can use this to left click a visible icon
|
||||
in the system tray. I had to specifically say
|
||||
visible icon as there may be many invisible
|
||||
@ -384,15 +420,17 @@ system tray icons:
|
||||
error checking is performed and this method will
|
||||
more then likely be moved/renamed in the futures.
|
||||
|
||||
:``RightClickSystemTrayIcon(button)``: Similar to ``ClickSytemTrayIcon`` but performs
|
||||
a right click.
|
||||
:``RightClickSystemTrayIcon(button)``: Similar to ``ClickSytemTrayIcon`` but
|
||||
performs a right click.
|
||||
|
||||
|
||||
Often when you click/right click on an icon - you get a popup menu. The thing to
|
||||
remember at this point is that the popup menu is part of the application being
|
||||
automated not part of explorer.
|
||||
|
||||
e.g. ::
|
||||
e.g.
|
||||
|
||||
::
|
||||
|
||||
# connect to outlook
|
||||
outlook = Application().connect_(path = 'outlook.exe')
|
||||
|
Loading…
Reference in New Issue
Block a user