使用Selenium 3.0启动Firefox 46.0.1时获取IllegalStateException [英] Getting IllegalStateException while launching Firefox 46.0.1 using Selenium 3.0
问题描述
我有Selenium版本3.0.1和Firefox版本46.0.1. 在硒3.0.1 更改日志中,提到:
I have Selenium version 3.0.1 and Firefox version 46.0.1. In selenium 3.0.1 changelog it is mentioned that:
Geckodriver现在是自动执行Firefox的默认机制.这 是Mozilla针对该浏览器的驱动程序的实现,并且是 自动化Firefox 48及更高版本所需的
Geckodriver is now the default mechanism for automating Firefox. This is Mozilla's implementation of a driver for that browser, and is required for automating Firefox versions 48 and above
尽管我遇到错误:
java.lang.IllegalStateException:必须通过webdriver.gecko.driver系统属性设置驱动程序可执行文件的路径;有关更多信息,请参见 https://github.com/mozilla/geckodriver .可以从 https://github.com/mozilla/geckodriver/releases 下载最新版本.
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
在执行以下代码时:
@Test
public void test() {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.quit();
}
为什么我仍然收到此错误,但我使用的是Firefox版本< 48.0? 在Selenium 3.0.1中必须同时使用Geckodriver吗?
Why am I getting this error nevertheless I am using Firefox version < 48.0 ? Is it mandatory to use Geckodriver with Selenium 3.0.1 ?
如果进行以下更改,以上代码将正常工作:
Above code is working perfectly if I make following changes:
System.setProperty("webdriver.gecko.driver","path to geckodriver");
WebDriver driver = new FirefoxDriver();
推荐答案
您必须为所有Firefox浏览器设置以下属性,无论从selenium 3.0
开始的版本是什么:
you have to set the following property for all Firefox browsers irrespective of the version from selenium 3.0
onwards :
System.setProperty("webdriver.gecko.driver","path to geckodriver");
Geckodriver现在是自动执行Firefox的默认机制.这是Mozilla针对该浏览器的驱动程序的实现,并且是自动化Firefox 48及更高版本所必需的
Geckodriver is now the default mechanism for automating Firefox. This is Mozilla's implementation of a driver for that browser, and is required for automating Firefox versions 48 and above
设置路径为必填项.
如果要在Firefox 47或更低版本上运行测试,请将Firefox驱动程序功能木偶"设置为false.
If you want to run the tests on Firefox 47 or before, set the Firefox driver capability "marionette" to false.
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false); // to disable marionette.
WebDriver driver = new FirefoxDriver(d);
这篇关于使用Selenium 3.0启动Firefox 46.0.1时获取IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!