What is the exact meaning of webdriver.chrome.driver and where this system property is located in Selenium?

SeleniumAutomation TestingTesting Tools

To launch the Chrome browser, we have to use the System.setProperty method. This method takes the parameters – webdriver.chrome.driver and the path of the chromedriver.exe file.

So webdriver.chrome.driver is basically the property name and the path of the chromedriver.exe is the value. Thus, the System.setProperty method is used to configure the browser driver path.

The Selenium client library communicates with the ChromeDriver via the JSON Wire Protocol. The Chrome browser driver acts like a link between the Selenium implementation code and the Chrome browser. The System.setProperty is the beginning line that requires to be added to our test prior creation of webdriver initialization.

Syntax

System.setProperty("webdriver.chrome.driver",
"C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");

Example

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ChromeBrwLaunch{
   public static void main(String[] args) {
      //set chromedriver.exe file path
      System.setProperty("webdriver.chrome.driver",
         "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("https://www.tutorialspoint.com/index.htm");
      // verify browser name and version with Capabilities class
      Capabilities cp = ((RemoteWebDriver) driver).getCapabilities();
      System.out.println("Browser: " + cp.getBrowserName());
      System.out.println("Version: " + cp.getVersion());
      //browser close
      driver.quit();
   }
}

Output

raja
Published on 06-Apr-2021 08:38:41
Advertisements