MSDN UK Team blog

Get all the latest Microsoft developer news, tools, downloads, tutorials and tips right here, every day.
Search Form
Unfiltered HTML
Developers code with microsoft

Introduction to Selenium WebDriver

Unfiltered HTML
Unfiltered HTML

Introduction to Selenium WebDriver

Rate This
  • Comments 1

Simon Stewart

This week’s Technical Article comes from Simon Stewart who works for Google as a Senior Software Engineer in Test. He's heavily involved in browser automation and Web UI testing so I asked him to give an introduction to one of the projects he's been working on for the past few years Selenium WebDriver. Over to Simon:

The worst bit about building webapps is verifying that they work. You might be in a corporate environment and only need to support one or two versions of IE. You might be working on a public facing site, and need to support the plethora of browsers out there. You might even be working on the cutting edge of the mobile Web and need to test with mobile browsers. Manually testing sites is, at best, a laborious process and is error prone. How can you make things easier?

This is where browser automation frameworks step in. They allow you to write a test using a language such as C# which can then be used for automated checks. Selenium 2's new WebDriver API is a lightweight, friendly browser automation API. It looks like this:

// Create a new WebDriver instance IWebDriver driver = new InternetExplorerDriver(); // Go to driver.Url = ""; // Find the search box and enter a search IWebElement searchBox = driver.FindElement(By.Name("q")); searchBox.SendKeys("selenium"); driver.FindElement(By.Name("go")).Click(); // Get the title of the loaded page Console.WriteLine(driver.Title);

There are a wealth of browser automation frameworks to choose from, so why pick Selenium WebDriver?

There are technical reasons. The API strikes a nice balance between simplicity and capability --- as you can see above, there are two main interfaces to deal with IWebDriver, representing a browser, and IWebElement, representing an element on a page. Intellisense will show you that the APIs are small and easy to navigate. Better still, the APIs focus on interacting with a page the same way that your users will: clicking and typing are accurately emulated. If the tests pass, you can be far more confident that your app works for your users.

There are social reasons too. Selenium also has a vibrant and active community, contributing lively and informative discussion in the online groups, and top-notch documentation on the project's site. Selenium is an Open Source project (using the generous Apache 2 license), and the core developers often offer suggestions and helpful advice on the lists. It's the most popular Open Source browser automation solution there is, so commercial support is also easy to come by. Selenium WebDriver is also a mature project, being a key part of the testing infrastructure of many companies, including Google.

Selenium WebDriver also supports testing on leading browsers from IE (6 all the way to 9!), through Firefox, Chrome and Opera, to mobile browsers such as the Android and iPhone browsers. This is a broader range of devices and browsers than many commercial tools.

No mention of the wide range of browsers supported by Selenium WebDriver can go by without also mentioning the support and help of the browser vendors. Both Opera and Chrome have support for WebDriver baked-in, meaning that your tests run lightning fast. Mozilla are involved with the project, working on improving the support for Firefox and their mobile browsers. The project is also taking the first steps to turn Selenium WebDriver from a wildly popular browser automation framework into a W3C standard.

If this sounds interesting, head over to and grab the latest version and try it out!

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post