我开始学习Selenium(第5天)并使用Gecko驱动程序启动Mozilla并收到以下错误:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\dev\geckodriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95)
我复制了代码(在eclipse中重新输入):
package mypackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myClass {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\dev\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://newtours.demoaut.com/");
driver.quit();
}
}
我的Geckodriver路径是C:\ dev \ Geckodriver 我看到同一个问题被多次询问,但没有看到上述信息。
答案 0 :(得分:0)
您需要从this链接下载geckodriver.exe
,如果没有gecko驱动程序,则无法运行firefox 49.0。下载后解压缩并存储在您计算机上的任何位置,然后按照此代码操作。为此使用Selenium 3.0.1版。
如果您使用的是旧版本的硒,那么您必须使用
WebDriver driver = new MarionetteDriver();
取代
WebDriver driver = new FirefoxDriver();
从以下链接下载gecko驱动程序:https://github.com/mozilla/geckodriver/releases
System.setProperty("webdriver.gecko.driver","C:\\dev\\geckodriver.exe"); // you have to select you path of gecko driver where you placed it after download and unzip.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");