Configure Selenium WebDriver to use Chrome

0 votes

As of 2015, the WebDriver specification became part of the W3C standard. The drivers are external, to make it more robust. We need to set the path to the driver executable in order to use the specific driver. (use `chmod +x [filename]` to make it executable on UNIX based systems) This section describes how to use Chrome.

Download the latest chromedriver from the following location: https://sites.google.com/a/chromium.org/chromedriver/downloads

@Test
public void useChromeDriver() {
  // Start browser
  System.setProperty("webdriver.chrome.driver", FileUtil.findFileOnPath("mac/chromedriver"));
  final ChromeDriver driver = new ChromeDriver();
  
  // Open website
  driver.get("http://www.selenium-in-action.io");
  
  // Close browser
  driver.quit();
}

Find file on path

public class FileUtil {

  public static String findFileOnPath(final String fileName) {
    if (new File(FileUtil.class.getClassLoader().getResource(fileName).getPath()).canExecute()) {
      return FileUtil.class.getClassLoader().getResource(fileName).getPath();
    } else {
      return new File("src/main/resources/" + fileName).getAbsolutePath();
    }
  }

}
Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/configure-selenium-webdriver-to-use-chrome/
Twitter
LinkedIn
Configure Selenium WebDriver to use Internet Explorer
Configure Selenium WebDriver to use FireFox

Leave a Reply

Your email address will not be published. Required fields are marked *