In Selenium 2 - Java, what's the difference between

ChromeDriver driver = new ChromeDriver();

and

WebDriver driver = new ChromeDriver();

? I've seen both of these used in various tutorials, examples, etc and am not sure about the difference between utilizing the ChromeDriver vs WebDriver objects.


Satish's answer is correct but in more layman's terms, ChromeDriver is specifically and only a driver for Chrome. WebDriver is a more generic driver that can be used for many different browsers... IE, Chrome, FF, etc.

If you only cared about Chrome, you might create a driver using

ChromeDriver driver = new ChromeDriver();

If you want to create a function that returns a driver for a specified browser, you could do something like the below.

public static WebDriver startDriver(Browsers browserType)
{
    switch (browserType)
    {
        case FIREFOX:
            ...
            return new FirefoxDriver();
        case CHROME:
            ...
            return new ChromeDriver();
        case IE32:
            ...
            return new InternetExplorerDriver();
        case IE64:
            ...
            return new InternetExplorerDriver();
        default:
            throw new InvalidParameterException("Unknown browser type");
    }
}
public enum Browsers
{
    CHROME, FIREFOX, IE32, IE64;
}

... and then call it like...

WebDriver driver = startDriver(Browsers.FIREFOX);
driver.get("http://www.google.com");

and depending on what browser you specify, that browser will be launched and navigate to google.com.


WebDriver is an interface, while ChromeDriver is a class which implements WebDriver interface. Actually ChromeDriver extends RemoteWebDriver which implements WebDriver. Just to add Every WebDriver like ChromeDriver, FirefoxDriver, EdgeDriver are supposed to implement WebDriver.

Below are the signatures of ChromeDriver and RemoteDriver classes

public class ChromeDriver extends RemoteWebDriver
implements LocationContext, WebStorage {}

public class RemoteWebDriver implements WebDriver, JavascriptExecutor,
FindsById, FindsByClassName, FindsByLinkText, FindsByName,
FindsByCssSelector, FindsByTagName, FindsByXPath,
HasInputDevices, HasCapabilities, TakesScreenshot {}