【问题标题】:Exception in thread "main" java.lang.IllegalStateException: thrown?线程“主”java.lang.IllegalStateException 中的异常:抛出?
【发布时间】:2017-03-16 10:51:21
【问题描述】:

我尝试下载新的 chrome 驱动程序并将其添加到我的驱动程序文件夹中,但它仍然抛出相同的错误。

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

    public class gmail {

    public static void main(String[] args) {


        WebDriver driver = new ChromeDriver();
        driver.get("https://mail.google.com");
        driver.findElement(By.id("Email")).sendKeys("********");
        driver.findElement(By.id("next")).click();
        driver.findElement(By.id("Passwd")).sendKeys("********");
        driver.findElement(By.id("signIn")).click();    
     }

    }

Error displayed:

    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:197)

【问题讨论】:

  • 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

标签: java selenium selenium-webdriver selenium-chromedriver selenium-firefoxdriver


【解决方案1】:
System.setProperty("webdriver.chrome.driver", "location/of/chromedriver/in/system");
WebDriver chromeDriver = new ChromeDriver();

【讨论】:

  • 尝试使用它但没有用,稍后尝试:System.setProperty("webdriver.chrome.driver", gmail.class.getClassLoader().getResource("drivers/chromedriver")。获取路径());它奏效了。
猜你喜欢
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 2017-01-28
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多