Selenium is one of the coolest tools out there for developers. It lets you automate web browsing. It has API’s for several languages and support for the “big 4” browsers.

There are actually two seperate projects here. One is the WebDriver, which they describe as, “a collection of language specific bindings to drive a browser.” If that means nothing to you, that is okay. Think of it as an API for the browser. The other product is Selenium IDE, which works with a handy browser extension that can work as an automation tool on it’s own or can be used to “record” bits of activity and export generated scripts in whatever supported language you are using WebDriver with.

We will get to that last part in a bit, but first, let me give you an example of how the API works. First of all, you’ll need to install WebDriver. All the info you need for that is here. I am using Python so if you want to run my test code, you will need the correct bindings. If you want to jump right in, here is the WebDriver API.

Okay, now that you have everything installed, we can make sure it is working. Hop in python interactive mode and try this:

from selenium import webdriver

# Opens browser
browser = webdriver.Firefox()

# Grabs a really cool website

# Looks for <li> items in page
basket = browser.find_elements_by_tag_name(li)

# Prints out the text inside all of the FirefoxWebElement eggs
for egg in basket[1:-1]:

Pro tip: Whenever you are playing with a new API and not sure about return objects you can check their type with type(egg) and check their methods with dir(egg). I like to do something like this - pprint(dir(egg)) - to get a clean list.

Neat, right?

There are all sorts of things you can do with the webdriver bindings. You can click buttons, input text to forms, try to break things. It’s a lot of fun. It is also very useful. If you haven’t yet, take a look through the docs to find some inspiration.

The first time I used Selenium was before I knew any programming at all. I was trying to solve a specific problem. I was trying to get hockey stats off of a website without copy/pasting pages and pages of tables. After countless hours of googling and seeing a lot of things that were way over my head I found Selenium IDE. I never did quite figure out the whole thing back then, but I did manage to get it installed and found a new appreciation for what programming was good for.

Check back soon! Part 2 is on its way with a dive into Selenium IDE and generating simple test scripts. Later on, I will go over some more advanced testing strategies using both tools and I might even drop in some basic web scraping.

Good luck and happy coding!