How do I open Chrome in selenium WebDriver?

We can open Chrome browser in Selenium webdriver. We can launch Chrome by instantiating an object of the ChromeDriver class with the help of the below statement.

WebDriver driver = new ChromeDriver();

Next we have to download the chromedriver and configure it to our project by following the below step by step processes −

  • As per version of the Chrome browser in the system, we have to select the download link. The next page shall be navigated where links to chrome drivers compatible with various operating systems are present.

  • After selecting the chrome driver as per the system configuration for download, a zip file gets created. We need to extract that and save the chromedriver.exe file at any location.

Let us discuss how to configure chromedriver with System properties within the Selenium code −

  • Add the System.setProperty method in the code which takes the browser type and the path of the chromedriver executable path as parameters.

System.setProperty("","<chromedriver path>");


Code Implementation

import org.openqa.selenium.WebDriver;
public class ChromeBrw{
   public static void main(String[] args) {
      // creating object of ChromeDriver
      WebDriver driver = new ChromeDriver();
      // to configure the path of the chromedriver.exe
      System.setProperty("", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      String url = "";