Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system

时间:2017-08-05 11:46:01

标签: java selenium

Following previous related issues posted and given resolution, I tired everything but still getting same error for FireFox, Chrome & Internet Explorer.

import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.firefox.FirefoxDriver;


 public class Search {

 public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    System.getProperty("webdriver.gecko.driver",
            "C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-
  win64\\geckodriver.exe");
    driver.get("http://www.wikipedia.org");
    WebElement link;
    link = driver.findElement(By.linkText("English"));
    link.click();
    Thread.sleep(5000);
    WebElement searchbox;
    searchbox = driver.findElement(By.id("searchInput"));
    searchbox.sendKeys("Software");
    searchbox.submit();
    Thread.sleep(5000);
    driver.quit();

3 个答案:

答案 0 :(得分:0)

Shouldn't that be System.setProperty() instead of .getProperty()?

System.setProperty("webdriver.gecko.driver, "C:\\Users\\...\\geckodriver.exe");

答案 1 :(得分:0)

在驱动程序初始化之前使用该gecko驱动程序系统属性 所以第一行gecko属性和下一行驱动程序= new so so ..

答案 2 :(得分:0)

使用.setProperty并在提供webdriver路径后声明它

System.setProperty("webdriver.gecko.driver",
            "C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();