Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property

前端 未结 6 1025
清酒与你
清酒与你 2020-11-22 05:01

I am trying to launch Mozilla but still I am getting this error:

Exception in thread \"main\" java.lang.IllegalStateException: The path to the driver

6条回答
  •  旧巷少年郎
    2020-11-22 05:18

    Every Driver service in selenium calls the similar code(following is the firefox specific code) while creating the driver object

     @Override
     protected File findDefaultExecutable() {
          return findExecutable(
            "geckodriver", GECKO_DRIVER_EXE_PROPERTY,
            "https://github.com/mozilla/geckodriver",
            "https://github.com/mozilla/geckodriver/releases");
        }
    

    now for the driver that you want to use, you have to set the system property with the value of path to the driver executable.

    for firefox GECKO_DRIVER_EXE_PROPERTY = "webdriver.gecko.driver" and this can be set before creating the driver object as below

    System.setProperty("webdriver.gecko.driver", "./libs/geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    

提交回复
热议问题