Web Automation Using Selenium
  • About The Book
  • Selenium
    • Introduction
      • What is testing and why?
      • What is Selenium and Why?
    • Getting Started
      • Audience
      • Prerequisite
      • Set up
      • Getting Started - Hello World..!!
      • What are drivers
    • Locators
      • CSS Selectors
      • XPath Selector
    • WebDriver
      • WebDriver Methods
      • WebDriver Types
    • WebElement(s)
      • WebElement Methods
      • Looping Through WebElements
    • Waits In Selenium
  • TestNG
    • Introduction
    • TestNG Setup
    • First Test Script
    • Some of the features of TestNG
    • TestNG Annotations
      • @Test
      • @DataProvider
  • Maven
    • Introduction
  • Framework Development
    • Introduction
    • Building Framework
      • Technology Stack
      • Page Object Model (POM)
      • Setup
      • What our framework contain
      • Packages
        • Context
        • Factory
        • Listeners
        • Pages
      • Creating first automation test
  • Common Interview Questions
    • Selenium-Related
Powered by GitBook
On this page

Was this helpful?

  1. Selenium
  2. WebDriver

WebDriver Types

Different types of WeDriver implementations and their set up

PreviousWebDriver MethodsNextWebElement(s)

Last updated 5 years ago

Was this helpful?

As discussed WebDriver is an interface and there are several implementations of the same in Selenium. Selenium supports most of the web browsers and provides implementations for them. Some of the popular ones are

  • Chrome

  • FireFox

  • Safari

  • etc.,

Example:

WebDriver driver = new ChromeDriver();
//or
WebDriver driver = new FirefoxDriver();
//or
WebDriver driver = new SafariDriver();

In order to make these implementations work we need one more component which is called webdriver executable file. (In short these are the binary files which help in converting java code to machine understandable instructions in order to make browser work).

Each of WebDriver implementations have their own binaries depending on the operating system.

One of two ways that selenium can use these binaries are,

  1. We need to download these driver binaries and keep them in the root of the project. Or,

  2. Before creating the instance of web driver we need to set the path for the binaries.

Example:

//For Chrome browser
System.setProperty("webdriver.chrome.driver","/path-to-driver.exe");
WebDriver driver = new ChromeDriver();

//For Firefox browser
System.setProperty("webdriver.gecko.driver","/path-to-driver.exe");
WebDriver driver = new FirefoxDriver();

If we don't keep the binaries in root or set the path selenium is going throw an exception saying webdriver path has not been set.

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Check here