Photo from Chile

Getting Started with WebDriver (a Browser Automation Tool)

A few weeks ago during MXUnit Office Hours, Bill Shelton demonstrated using WebDriver to create functional tests in Java. It was a pretty cool demo and I meant to give it a whirl for a while, but only got around to doing it this weekend. I had to refer back to the recording of the session a number of times, so I thought it would be worthwhile to document the steps to get a project up and running in Eclipse that uses WebDriver. Let's start with some background.

What is WebDriver?

WebDriver is a tool that allows you to write code, in a number of languages, that automates a browser and allows you to interrogate what is rendered by the browser. You can use these features to created automated tests of a web application. You may be familiar with a tool called Selenium, which does similar things, but works within the context of a web browser itself. The Selenium project and the WebDriver project are merging to create Selenium 2.0. That project is a work in progress, but there's nothing to stop you from experimenting with WebDriver right now.

For a bit more of an official definition, here's some info from the Selenium 2.0 and WebDriver page at SeleniumHQ:

WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that's easy to explore and understand, which will help make your tests easier to read and maintain. It's not tied to any particular test framework, so it can be used equally well with JUnit, TestNG or from a plain old "main" method.

WebDriver uses a different underlying framework from Selenium's javascript Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a javascript core embedded within the browser, therefore it is able to avoid some long-running Selenium limitations.

WebDriver's goal is to provide an API that establishes

  • A well-designed standard programming interface for web-app testing.
  • Improved consistency between browsers.
  • Additional functionality addressing testing problems not well-supported in Selenium 1.0.

I hope to write a number of posts about working with WebDriver. This first post will be a quick guide to setting up an Eclipse project and getting WebDriver to interact with a web page. Let's get started.


Hi Bob,
Have you seen Badboy (
It does something similar but uses a graphical interface. Badboy is very easy to use (actually darned simple - just open up BB, navigate through the site or test case and that's it).

Badboy is also scriptable, using jScript. The chief downside to it that you have to have IE on your machine.

I use it to develop test cases etc. One thing that makes it very useful is that you can export your badboy saved files to use as jMeter load testing xml configuration file.

Currently I use it to automate a download data files from a site that uses password protection.

# Posted By Larry C. Lyons | 5/17/10 2:59 PM
That sounds interesting, Larry. I've never even heard of it before. I went to the site and took a look. It looks kind of like Selenium IDE, but for IE. Does it support any form of asserts? That is, you can automate the steps, but can you check to see whether you are getting the results you expected via scripting?
# Posted By Bob Silverberg | 5/17/10 5:06 PM
Yes. You can set up assertions either using the GUI, through scripting and through db access. You can set up variables etc with it. I'd be able to give more details but I'm heading home on the train, and don't have a copy on my laptop here.
# Posted By Larry C. Lyons | 5/17/10 5:11 PM
Great post, Bob. Keep it coming!

Hey, one minor point (and it was my shortcomming) ... the URL for the Javadoc should omit the 'index.html' and be : . Eclipse still says the location "might be valid" or some such.

# Posted By bill shelton | 5/18/10 3:18 PM
It worked for me when I entered the full URL including the index.html, and I didn't get any validation warnings. Or maybe it didn't work - maybe it just accepted my input and ignored the Javadoc location? What should I do to check?
# Posted By Bob Silverberg | 5/18/10 4:06 PM
Bob, One way to see if your Eclipse project has a valid Javadoc location is to hover your cursor over an [Webdriver] object in some code. If the Javadoc is attached correctly, a dialog will appear with the Javadoc description of the class. Then you can hit F2 to bring focus to the dialog, which then gives you a couple of additional buttons, one of which is a link to the full Javadoc. However, if the Javadoc is *not* attached correctly, the initial dialog will simply say "No source or Javadoc attached ..." or some such.

Larry, thanks for the info to Badboy! This might be a winner for one particular Win32/IE project I'm working on. Though not open source, it appears to be quite reasonable at 45USD or less.

# Posted By bill shelton | 5/19/10 6:43 AM
Aha, of course you are correct, Bill. The Javadoc wasn't successfully linked. I've changed the text in the post to remove the index.html portion of the link. Thanks!
# Posted By Bob Silverberg | 5/19/10 7:03 AM
In what context does this test run in? Do we need to install
and configure a Remote Server?
When I run this test I get A NoSuchElementFoundException. Th
The website is not even been requested.

Please let me know what extra configuration is required.

Thanks in advance
# Posted By Singh | 6/10/10 9:34 AM
@Singh: No configuration was required on my machine, although you do need Firefox installed. I'm just learning this stuff myself, so I'm not sure I can help you much if what I documented isn't working. Perhaps you could try the website?
# Posted By Bob Silverberg | 6/17/10 10:26 AM
hi Bob ,
I wrote a webdriver script which will do some update
on UI and then it needs to verify the oracle datadase to
check whether the update is successful or not in a
particular DB table . How can I check
the DB part using webdriver .
# Posted By Aroma | 7/9/10 4:28 PM
i got the following error :

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
   FirefoxDriver cannot be resolved to a type

   at test.test.main(

what is the problem ??
# Posted By Viet | 7/8/11 5:40 AM
I guess you are missing this import

import org.openqa.selenium.firefox.FirefoxDriver;
# Posted By Bill Mackie | 9/1/11 5:36 AM
I ran into the same problem Viet says. I fixed it by using the driver for internet explorer:
WebDriver driver = new InternetExplorerDriver();
Of course you have to import the corresponding library...

Tried chrome driver but it just kills the CPU, consumes too much resources...

I know selenium 2 with web driver is ready now, but their documentation sucks... Yesterday I tried every possible way to make it work on windows 7 but it was impossible, the maven connection never worked for me and the tutorial they have just tells you to get Maven information somewhere else...
I canĀ“t believe someone releases a tool with such a crappy documentation for the developers!
# Posted By Carlos H | 9/1/11 11:28 AM
I am getting below error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
   Cannot instantiate the type WebDriver

   at test.Test.main(
# Posted By poonam | 9/21/11 7:16 AM
Hey poonam,
could you provide more details on the error? Initially it look like missing references.
# Posted By rajeev | 9/21/11 11:20 AM
Its worked fine. Thanks for the great documentation
# Posted By Sheejan Joseph | 9/22/11 2:12 AM
It gives only this message, could not see more details on it
# Posted By poonam | 9/23/11 12:45 AM
It worked for me!
Do you have some documentation on how to create a build file using ant or maven?
# Posted By Kanchan | 10/10/11 10:36 PM
@Kanchan: Sorry, I do not.
# Posted By Bob Silverberg | 10/11/11 12:30 PM
Where can I download Selenium JavaDocs from to place on my local machine and then access javadocs by specifying the local path to it instead of using the URL? The URL is not working for me (probably because I am behind a proxy).
# Posted By Jeej | 11/2/11 7:09 AM
Thank you so much for this. I am new to automated testing and was trying to get eclipse set up with maven so I could use Selenium, but failing dismally. I'm all sorted now so thank you.
# Posted By EllsBells | 11/29/11 6:10 PM
Thanks for the demo! I was setup in no-time.
# Posted By Greg | 11/29/11 9:09 PM
Thank you so much for this informative post. I got my first webdriver script runnning. :) I couldn't find anything other resource on internet explaining intial setup so easily and nicely as you did. :)

# Posted By Black Swan | 12/22/11 4:03 AM
This is a great tutorial. Installed Eclipse and followed your instructions and was up and running in no time - only thing extra I had to do was to add

import org.openqa.selenium.firefox.FirefoxDriver;

as posted by Bill Mackie.

Many thanks!
# Posted By bslavuk | 12/29/11 8:49 PM
Quick and easy documentation fro the newbies. Thanks
# Posted By Megha | 3/6/12 3:47 PM
Very useful information. I got the selenium up and running within minutes.However, I still have issues launching IE 7. I get some exception saying
"Protected mode (enable or disable)". Not sure what it is
# Posted By Ranjani | 3/7/12 8:03 AM
Hey Bob,
This was pretty good piece of information.
What amaze me is the leverage of power of Java into test Automation.
I had been working around for 2 days just to evoke "FirefoxWebDriver" class. And I guess I was missing somewhere.
I came across this blog and my problem got resolved.
I am QTP professional and my interest is inclined towards Java.
I'll be happy to know if have all the features of QTP.

Thank you once again and keep writing.
# Posted By Pankaj Dhapola | 3/29/12 3:31 AM
Hi there, great post, clearly explained and just what I was looking for

i've followed all the instructions and added the:
import org.openqa.selenium.firefox.FirefoxDriver;

but i'm getting the following message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
   at webdriverpackage.Test.main(
Caused by: java.lang.ClassNotFoundException:
   at$ Source)
   at Method)
   at Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   ... 1 more

i'm a total novice so any help would be greatly appreciated
# Posted By Omar | 4/11/12 6:08 AM
Fixed it, i didn't add the selenium server to the lib
its working now and ran successfully

# Posted By Omar | 4/11/12 6:28 AM
Thanks a lot for the post. was really helpful.
# Posted By Farish | 9/24/12 9:58 AM
Thanks for this, I had been beating my head against the wall trying to get webdriver set up and the other instructions I had found were just not detailed enough.

Bill Mackie's above comment regarding adding the import "import org.openqa.selenium.firefox.FirefoxDriver;" should be added in, seems like it doesn't work without that.

Also might be helpful to note that if someone simply copies and pastes your code (as I did), the line numbers must be removed before it will work.
# Posted By Jed | 10/26/12 7:45 PM
Have u any material for selenium web driver ?
# Posted By Bhanu | 12/11/12 1:09 AM
Has anyone had issues with JavaDoc not working correctly, even following this blog? Particularly if they've customized & wrapped WebDriver code within their framework (e.g. not directly access WebDriver in tests). I tried it out and it only partially works. JavaDoc autocomplete tooltip shows info for WebDriver related class constructors, but shows no attached source message when trying to view doc info for class methods. I'm linking the JavaDoc URL to the Selenium standalone server JAR (v2.28) if that makes any difference. This sucks as most people (or me at least) care more about JavaDoc for methods and properties than class constructors...
# Posted By David Luu | 2/8/13 3:36 PM
I followed the above given steps and was able to achieve the desired result.Thanks.
# Posted By mkrishnachaitanya | 9/24/13 12:22 AM
Hi Bob,

Your blog helped me solve the path to java doc identifying problem, its now all setup correctly and I am not seeing any errors

But I am trying to automate using IE webdriver and when I run following code on eclipse I am getting error
package webtest2;

import org.openqa.selenium.WebDriver;

public class thirdprogram {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      // System.setProperty("", "C:\\IEDriverServer_x64_2.35.3\\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();


Started InternetExplorerDriver server (64-bit)
Listening on port 13277
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Could not get document from window handle (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8.89 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02'
System info: host: 'PRADEEPM-PC', ip: '', 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info:
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at org.openqa.selenium.remote.ErrorHandler.createThrowable(
   at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(
   at org.openqa.selenium.remote.RemoteWebDriver.execute(
   at org.openqa.selenium.remote.RemoteWebDriver.startSession(
   at org.openqa.selenium.remote.RemoteWebDriver.startSession(
   at webtest2.thirdprogram.main(

# Posted By pradeep | 10/22/13 6:59 PM
Hi Pradeep. Thanks for your comment. Unfortunately I have no experience with the IEDriver, so I don't have much advice to offer. I would suggest posting a question to the WebDriver google group at!forum/webdriver
# Posted By Bob Silverberg | 10/22/13 9:53 PM
Can you please provide details on about writing a JUnit test that uses WebDriver so we can do some actual functional testing with it
# Posted By Sonali | 5/29/14 4:09 AM
I don't use JUnit so I cannot really provide that information. I am confident that a Google search would yield a ton of results though.
# Posted By Bob Silverberg | 5/29/14 8:01 AM