0

I have applies the all code & still getting error to open chrome browser in selenium. I have set the property also for gecko-driver. pls check the code & give some solution

I am getting this 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:847) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at hps1.HPS.main(HPS.java:10)

HPS.java

package hps1; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class HPS { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver=new ChromeDriver(); //System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe"); System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe"); // Open driver.get("http://www.facebook.com"); // Maximize browser driver.manage().window().maximize(); } } 

    2 Answers 2

    3

    You are initializingdriver first and then setting the system property thats why it is throwing an error. Moving the Property setting line above the driver initialization will do the job for you.

    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe"); WebDriver driver=new ChromeDriver(); // Open driver.get("http://www.facebook.com"); // Maximize browser driver.manage().window().maximize(); } 
    0
      0

      Look,this is the first step,you should tell where the driver is and what type it is.

       System.setProperty("webdriver.chrome.driver", "D:\\browser_driver\\chromedriver\\chromedriver.exe"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--headless"); //谷歌浏览器无头模式 // chromeOptions.addArguments("no-sandbox");//禁用沙盒 driver= new ChromeDriver(service,chromeOptions);//使用端口 

      And then build a new ChromeDriver is ok.You see the exception message tells you that the driver is not set well,so you should set it first and then construct a object later.

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.