Setting Up Selenium with Python

June 7, 2010

1.    Install Selenium IDE Firefox extension

- Firefox extension allows you to record and playback actions
- Allows the user to edit the source and save as various file types such as HTML, Ruby,
- Allows the user to select fields by name, id, supports xpath

Record and playback (html) file to verify it works.

2.    Install Selenium RC: http://selenium.googlecode.com/files/selenium-remote-control-1.0.3.zip

a.    Extract to C:\SeleniumRC folder, or anywhere you want to work with it

b.    Check Java on your machine. Open command prompt and enter

i.    Java –version (make sure you have 1.5 and above)

ii.      http://www.cs.mcgill.ca/~cs202/2009-01/other/jdk-configuration–vista.pdf

c.    First start the Selenium RC server by opening command prompt and enter:

i.     C:\>java -jar c:\SeleniumRC\selenium-server-1.0.3\selenium-server.jar –multiwindow

d.    Open a text file and enter the above command (without the C:\>) Then save as SeleniumRC.bat and you can run the server from your shortcut.

3.    Install Python at: http://activestate.com/Products/activepython/index.mhtml or http://www.pythonmac.org/

If you don’t know which version to use, start with Python 2.6.5; more existing third party software is compatible with Python 2 than Python 3 right now. Python 3 is backwards INCOMPATIBLE

a.    Set your environment so your command window knows to run it:

i.    set path=%path%;C:\python26

ii.    set path=%path%;C:\ python31

iii.    Open command prompt and type path to see paths set

iv.    Make directly executable by #! /usr/bin/env python in python script

v.    To run open command window and go to file: C:>python script.py or use PythonWin/IDLE

b.    Go to your SeleniumRC directory C:\SeleniumRC and open selenium-python-client-driver-1.0.1

c.    Copy the module with the Selenium’s driver for Python (selenium.py) in the folder C:/Python25/Lib (this will allow you to import it directly in any script you write).

4.    Go to Selenium IDE and export a test script to Python under :

a.    Options -> Export -> Python-Selenium RC.

b.    Save the file as .py

5.    To run your Python script with Selenium RC:

a.    Start Selenium RC server with java command above if it is not already started

b.    Open new command window and go to directory of Python script: cd C:\pythonautomation

c.    Enter script name to run: search.py

Previous post: Sync NI – Technology, Science & Innovation : News, Events & Jobs …

Next post: Automating with TestComplete at Naqoosh