Skip to content

Commit

Permalink
Fixing up readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
bil-bas committed Aug 7, 2017
1 parent 4eb928d commit 322ef4c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 40 deletions.
104 changes: 65 additions & 39 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# The uiautomation module

This module is for UIAutomatoin on Windows(Windows XP with SP3, Windows Vista, Windows 7 and Windows 8/8.1/10).
It supports UIAutomatoin for the applications which implmented UIAutomation Provider, such as MFC, Windows Form, WPF, Modern UI(Metro UI), Qt and Firefox.
This module is for UIAutomation on Windows(Windows XP with SP3, Windows Vista, Windows 7 and Windows 8/8.1/10).
It supports UIAutomation for the applications which implmented UIAutomation Provider, such as MFC, Windows Form, WPF, Modern UI(Metro UI), Qt and Firefox.

uiautomation is shared under the Apache Licence 2.0.
This means that the code can be freely copied and distributed, and costs nothing to use.

You can install uiautomation by "pip install uiautomation"
You can install uiautomation with:

Run 'C:\Python36\Scripts\automation.py -h' for help.
Run 'C:\Python36\Scripts\automation.py -h' for help.
Run automate_notepad_py3.py to see a simple demo.
pip install uiautomation

Run `demos\notepadtop.py` to see a simple demo.

If "RuntimeError: Can not get an instance of IUIAutomation" occured when running uiautomation.py,
You need to install update [KB971513](https://support.microsoft.com/en-us/kb/971513) for your Windows.
Expand All @@ -28,34 +28,44 @@ Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Win

--------------------------------------------------------------------------------
How to use uiautomation?
run '**automation.py -h**' or '**uiautomation.py -h**'

C:\PythonXX\Scripts\automation.py -h

Where XX is your python version, such as 27 or 33 or 36. If you add Scripts/ to your PATH,
then just `automation.py` will run the script.

![help](images/uiautomation-h.png)
Understand the arguments of uiautomation, and try the following examples
**uiautomation.py -r -d 1 -t 0**, print desktop(the root of control tree) and it's children(top level windows)
**uiautomation.py -t 0**, print current active window's controls
Understand the arguments of uiautomation, and try the following examples

print desktop(the root of control tree) and it's children(top level windows):

C:\PythonXX\Scripts\automation.py -r -d 1 -t 0

print current active window's controls:

C:\PythonXX\Scripts\automation.py -t 0

run notepad.exe, run uiautomation.py -t 3, swith to Notepad and wait for 5 seconds
run `notepad.exe`, run `C:\PythonXX\Scripts\automation.py -t 3`, switch to Notepad and wait for 5 seconds

uiautomation will print the controls of Notepad and save them to @AutomationLog.txt:

ControlType: WindowControl ClassName: Notepad
  ControlType: EditControl ClassName: Edit
    ControlType: ScrollBarControl ClassName:
      ControlType: ButtonControl ClassName:
      ControlType: ButtonControl ClassName:
    ControlType: ScrollBarControl ClassName:
      ControlType: ButtonControl ClassName:
      ControlType: ButtonControl ClassName:
    ControlType: ThumbControl ClassName:
  ControlType: StatusBarControl ClassName:
    ControlType: TextControl ClassName:
    ControlType: TextControl ClassName:
...
ControlType: WindowControl ClassName: Notepad
  ControlType: EditControl ClassName: Edit
    ControlType: ScrollBarControl ClassName:
      ControlType: ButtonControl ClassName:
      ControlType: ButtonControl ClassName:
    ControlType: ScrollBarControl ClassName:
      ControlType: ButtonControl ClassName:
      ControlType: ButtonControl ClassName:
    ControlType: ThumbControl ClassName:
  ControlType: StatusBarControl ClassName:
    ControlType: TextControl ClassName:
    ControlType: TextControl ClassName:

run the following code
```python
import subprocess
from uiautomation import uiautomation as automation
import uiautomation as automation

print(automation.GetRootControl())
subprocess.Popen('notepad.exe')
Expand All @@ -65,23 +75,23 @@ notepadWindow.SetTopmost(True)
edit = notepadWindow.EditControl()
edit.SetValue('Hello')
edit.SendKeys('{Ctrl}{End}{Enter}World')

```

automation.GetRootControl() returns the root control
automation.WindowControl(searchDepth = 1, ClassName = 'Notepad') creates a WindowControl, the parameters specify how to search the control
the following parameters can be used
searchFromControl = None,
searchDepth = 0xFFFFFFFF,
searchWaitTime = SEARCH_INTERVAL,
foundIndex = 1
Name
ClassName
AutomationId
ControlType
Depth

See Control.\_\_init\_\_ for the comment of the parameters
See automation_notepad_py3.py for a detailed example
* searchFromControl = None,
* searchDepth = 0xFFFFFFFF,
* searchWaitTime = SEARCH_INTERVAL,
* foundIndex = 1
* Name
* ClassName
* AutomationId
* ControlType
* Depth

See `Control.__init__()` for the comment of the parameters
See `demos\automation_notepad_py3.py` for a detailed example

--------------------------------------------------------------------------------
Another UI tool inspectX86.exe or inspectX64.exe supplied by Microsoft can also be used to see the UI elements.
Expand Down Expand Up @@ -117,4 +127,20 @@ Batch rename pdf bookmark
![bookmark](images/rename_pdf_bookmark.gif)

Pretty print dir
![PrettyPrint](images/pretty_print_dir.png)
![PrettyPrint](images/pretty_print_dir.png)


Building as package
-------------------

* Update VERSION in uiautomation/version.py

* Install build requirements (wheel):

pip install -r requirements-dev.txt

* Build wheel:

python setup.py bdist_wheel

.whl file will be in the dist directory.
1 change: 0 additions & 1 deletion requirements.txt → requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
wheel==0.29.0
pywin32>=221

0 comments on commit 322ef4c

Please sign in to comment.