Home > python, web > Selenium, a web application testing system

Selenium, a web application testing system

With Selenium, you can automate the tests of web applications. Actually, I wanted to do something else with it and it turned out that selenium is designed for something else. Anyway, here I sum up what I learned about selenium.

If you want a 2-minute introductory video, watch this.


The download page is here. You’ll have to download the selenium server and launch it. It’s a JAR file. The client scripts that you write to automate tests communicate with this server.

The Selenium IDE is a Firefox add-on for recording (and playing back) interactions with the browser. The add-on can export your interactions in various languages (Java, Python, Ruby, etc.). Strangely, the add-on didn’t support Firefox 4 when I tried it, so I had to force the installation with the Nightly Tester Tools add-on.


Here is a simple Python example to open a web page. The source is generated by the Selenium IDE:

#!/usr/bin/env python

from selenium import selenium
import unittest, time, re

class Untitled(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "http://www.ncbi.nlm.nih.gov/")

    def test_untitled(self):
        sel = self.selenium

        # my addition:
        text = sel.get_html_source()
        f = open('out.txt', 'w')

    def tearDown(self):
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":

Just for playing a bit with the code, I added some lines to save the HTML source of the page. I was hoping that it would save the post-AJAX version of a page, but no :( If you want the generated HTML source, you will need a different approach.


Categories: python, web Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: