This is my first blog; My first topic is Python with Autoit. Most of automation frameworks
are now designed with Selenium and Java/Ruby/Python etc.
I picked up python where selenium where limitation is automating the
windows object. But there is easy and alternative way to automate windows objects using python code with inherited autoit libraries.
Software Requirement:
1. Install Python (with any suitable version)
- https://www.python.org/downloads/
2. PyCharm
- https://www.jetbrains.com/pycharm/download/#section=windows OR
3. Eclipse - http://www.eclipse.org/downloads/
4. Install Autoit https://www.autoitscript.com/site/autoit/downloads/
4. Install Autoit https://www.autoitscript.com/site/autoit/downloads/
How to Install:
There are two options we can use:
1. Independent Autoit
plugin for python(Pyautoit):
a. Go to Python
installed location and open the script folder where pip.exe are
available (e.g. D:\Python36-32\Scripts)
b. Open command prompt
for above location and run
c. pip install -U pyautoit
2. Pywin32 package for
Python:
a. go to https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/ and download
the correct version based on your Python version and install.
b. or go to http://www.lfd.uci.edu/~gohlke/pythonlibs/ and download
the correct version of whl file (e.g. pywin32‑220.1‑cp36‑cp36m‑win32.whl).
c. Put
the pywin32‑220.1‑cp36‑cp36m‑win32.whl file into script folder
(e.g. D:\Python36-32\Scripts)
d. run pip install pywin32‑220.1‑cp36‑cp36m‑win32.whl
e. Once installation completed there is one pyfile in script folder with
name pywin32_postinstall.py.
f. Run the following
command in (Path : where python.exe is present e.g. D:\Python36-32\)
g. python.exe
Scripts\pywin32_postinstall.py –install
h. Other way to
install the Pywin32 : use pip install pypiwin32 (in valid path e.g.
D:\Python36-32\Scripts>pip install pypiwin32)
Basic Example
Example 1 (Independent Autoit Plugin
Pyautoit)
import autoit
autoit.run("notepad.exe")
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
autoit.win_close("[CLASS:Notepad]")
autoit.control_click("Notepad", "[CLASS:Button; INSTANCE:2]")
Note:
The autoit commands all use lower_case_with_underscores rather than
AutoItX's preferred CamelCase. Thus ControlSend becomes control_send, WinClose
becomes win_close, etc.
Example 2 (Pywin32)
from win32com.client import Dispatch
Auto = Dispatch("AutoItX3.Control")
Auto.Run("notepad.exe",'',5)
Auto.WinWaitActive("Untitled - Notepad")
Auto.Send("This is some text.")
Auto.WinClose("Untitled - Notepad")
Auto.ControlClick("Notepad","Do&n't Save","[CLASS:Button; INSTANCE:2]" )
If Any issue opening Notepad please follow the below mentioned steps:
Try the above code with following import
Open a command prompt window (cmd) as an administrator
Go to AutoItX directory (default on Windows 7 : cd C:\Program Files (x86)\AutoIt3\AutoItX\)
Type these two commands :
regsvr32.exe AutoItX3.dll
regsvr32.exe AutoItX3_x64.dll
Try the above code with following import
How to check installed plugins:
Go to Python installed location and open the script folder where pip.exe
are availble (e.g. D:\Python36-32\Scripts) open Command Prompt
Run pip list
No need to write and call independent autoit scripts. all code will be
in one language and easy to debug and modify.
THANKS
Comments
Post a Comment