繁体   English   中英

无法使用Chrome和Firefox在带有Java和BDD的Eclipse上运行Selenium

[英]Can not Running Selenium with Eclipse with Java and BDD using Chrome or Firefox

我正在尝试运行Selenium,但出现此错误,知道吗? 我正在使用硒3.0.0-beta2

这是错误:

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see 
https://github.com/mozilla/geckodriver. 
The latest version can be downloaded from 
https://github.com/mozilla/geckodriver/releases
 at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
atorg.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
 at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
 at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91)
 at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
 at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245)
 at 
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:220)
 at 
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:215)
 at 
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
 at 
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
 at 
CCRX.CCRX2.App.user_at_login_p3age(App.java:36)
 at ✽.Given User at login page(src/test/resources/loginpage.feature:5)

如提及的那样,根据您的要求从https://github.com/mozilla/geckodriver/releases下载gecko驱动程序(我的是Windows)。 解压缩并找到驱动程序。

在您的代码中添加这些,

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

另外,请确保您使用的是Firefox 48。

您可以尝试一次:

在main方法下用Selenium编写代码:

System.setProperty("webdriver.gecko.driver",
"path you downloaded/geckodriver.exe");// You have to set the Local path where you downloaded the driver.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("www.google.com");

我认为这可能对您有帮助。

您需要先指定驱动程序,然后再指定硒服务器。

对于硒3.0,参数的顺序已更改,如下所示:

java -Dwebdriver... -jar selenium-server.jar

到驱动程序可执行路径的路径必须由webdriver chrome驱动程序sys设置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM