goldb.org home

AS OF MAY 2008, THIS BLOG IS NO LONGER BEING UPDATED.
Visit the new blog at: http://coreygoldberg.blogspot.com



 Tuesday, April 10, 2007

Python and IEC - Stupid-Simple Windows Browser Automation

I have been using IEC lately for automating repetitive administrative tasks within my company:

IEC.py - Automating Internet Explorer with Python

IEC is a simple library with a nice API for automating an IE browser. I found it simple to work with for basic automation needs. I have also used it as the core of a small UI testing framework.

From Mayukh Bose:

IEC is a python library designed to help you automate and control an Internet Explorer window. You can use this library to navigate to web pages, read the values of various HTML elements, set the values of checkboxes, text boxes, radio buttons etc., click on buttons and submit forms.

Yeah I know.. pretty lame it only works with IE, but in the environment I was working in, the applications ran on *IE Only*.


A personal story:

My company is very analytical and detail oriented when it comes to tracking/planning project resource allocation. We track all sorts of projections, budgets, resources, etc. The workflow is basically: some business guys (no idea what they actually do) take data from some reports and enter them into some arcane hosted tracking software. This is done by entering copious amounts of data into web form after web form. Then they submit the form to run a report. Once that is finished, they cut & paste the data into MS Excel. Then they take the Excel spreadsheet and follow some wild sequence of copying, cutting, pasting, converting, running macros, graphing, etc. At the end of this, a few images are produced so some wizz-bang graphs can go into a monthly Powerpoint... wow.

So... I wrote a Python script that takes their input data, drives a web browser to do the report, screen scrapes the result, processes it, generates some fancy graphs with Matplotlib, and presents a web page with the results.  End result: Converted a multi-hour manual process into the click of an icon and 20 seconds of processing.

I could have done this with HTTP directly, but this UI automation technique made it very quick to develop; and it looked impressive ("whoa it's like.. making my browser move on its own").


To use IEC, you need the Python for Windows Extensions. If you use the ActiveState Python distribution, these are already included.

I used to use ActiveState Python for Windows programming (because I was a big fan of ActiveState Perl, where the installer and PPM package manager rocked). I recently spent close to an hour getting SSL (HTTP) to work with ActiveState.  I couldn't get it to work so I ditched it for the standard Python distro.


--
Happy Hacking.

#    Comments [4] |
Tuesday, April 10, 2007 6:32:13 PM (Eastern Standard Time, UTC-05:00)
Another option for firefox users is to use the great selenium IDE: http://www.openqa.org/selenium-ide/
It takes care of the most boring part: the clicking, selecting and form filling. You can save all your actions in a browser session. If you are really brave, you can save your session recording as a python/ruby/perl script and -- voilá! -- all the power of python is in your hands.
Wednesday, April 11, 2007 2:46:22 PM (Eastern Standard Time, UTC-05:00)
Hi Corey,
I work on ActivePython. May I ask what specific problems you had with SSL in ActivePython? Note that OpenSSL support was only added to ActivePython as of version 2.5.0 (fairly recently released) because we had to obtain crypto export approval from the government.

With ActivePython 2.5 I was able to do at least some basic automation of an HTTPS site.

>>> import IEC
>>> ie = IEC.IEController()
>>> ie.Navigate('https://www.wellsfargo.com/')
>>> ie.SetInputValue('query', 'account')
1
>>> ie.ClickButton(name="searchBtn")
1
Wednesday, April 11, 2007 3:08:28 PM (Eastern Standard Time, UTC-05:00)
Trent.
It wasn't an issue with IEC and ActivePython.
It was just trying make HTTPs requests with urllib.
I tried with ActivePython 2.4 and had no luck. Was that fixed in 2.5?

-Corey
Wednesday, April 11, 2007 4:43:01 PM (Eastern Standard Time, UTC-05:00)
Yes, ActivePython distros before 2.5 don't have SSL support (needed for HTTPS interaction).
Comments are closed.