-1

I executed below script in selenium webdriver:

package Facebook;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class facebooklogin {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver=new ChromeDriver();
        driver.get("https://www.facebook.com");
        driver.manage().window().maximize();

    }

}

Facing below error:

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 at com.google.common.base.Preconditions.checkState(Preconditions.java:172) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109) at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116) at Facebook.facebooklogin.main(facebooklogin.java:11)

EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40
sunil kumar
  • 1
  • 1
  • 1

1 Answers1

1

Please check your exception lines, which is saying - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; Selenium can't communicate directly with browsers, it needs a driver file which is provided by the browser providers. Here in Chrome browsers when you want to run the script you'll require chromedriver basically provided by Google. Downlaod the driver file and put it in your project, and add below lines before browser initialization.

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
promitheus
  • 67
  • 2
  • 13