Selenium webdriver 无法从Selenium Webdriver版本3.4.0启动Firefox浏览器

Selenium webdriver 无法从Selenium Webdriver版本3.4.0启动Firefox浏览器,selenium-webdriver,Selenium Webdriver,我面临一个问题,即我无法从64位Windows操作系统(Windows 7)上启动Selenium Webdriver 3.4.0版firefox。 目前,firefox版本52.0.2安装在我的机器上。 我还向库中添加了SeleniumJAR文件,但它仍然显示错误 我的代码: package sanity; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; publ

我面临一个问题,即我无法从64位Windows操作系统(Windows 7)上启动Selenium Webdriver 3.4.0版firefox。 目前,firefox版本52.0.2安装在我的机器上。 我还向库中添加了SeleniumJAR文件,但它仍然显示错误

我的代码:

package sanity;

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

public class Login
{
        public static void main(String[] args)    
        {
            WebDriver driver=new FirefoxDriver();    
            driver.close(); 
        }
}
Exception in thread "main" 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:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at sanity.Login.main(Login.java:18)
    1492944489305   geckodriver INFO    Listening on 127.0.0.1:12059
1492944489973   geckodriver::marionette INFO    Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1492944491445   addons.manager  ERROR   startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"  data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()@resource://gre/modules/AddonManager.jsm:700 < AddonManagerInternal.startup()@resource://gre/modules/AddonManager.jsm:870 < this.AddonManagerPrivate.startup()@resource://gre/modules/AddonManager.jsm:3033 < amManager.prototype.observe()@resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1677: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1492944492505   Marionette  INFO    Listening on port 50231
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2585: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
Apr 23, 2017 4:18:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
错误:

package sanity;

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

public class Login
{
        public static void main(String[] args)    
        {
            WebDriver driver=new FirefoxDriver();    
            driver.close(); 
        }
}
Exception in thread "main" 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:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at sanity.Login.main(Login.java:18)
    1492944489305   geckodriver INFO    Listening on 127.0.0.1:12059
1492944489973   geckodriver::marionette INFO    Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1492944491445   addons.manager  ERROR   startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"  data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()@resource://gre/modules/AddonManager.jsm:700 < AddonManagerInternal.startup()@resource://gre/modules/AddonManager.jsm:870 < this.AddonManagerPrivate.startup()@resource://gre/modules/AddonManager.jsm:3033 < amManager.prototype.observe()@resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1677: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1492944492505   Marionette  INFO    Listening on port 50231
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2585: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
Apr 23, 2017 4:18:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
控制台:

package sanity;

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

public class Login
{
        public static void main(String[] args)    
        {
            WebDriver driver=new FirefoxDriver();    
            driver.close(); 
        }
}
Exception in thread "main" 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:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at sanity.Login.main(Login.java:18)
    1492944489305   geckodriver INFO    Listening on 127.0.0.1:12059
1492944489973   geckodriver::marionette INFO    Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1492944491445   addons.manager  ERROR   startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"  data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()@resource://gre/modules/AddonManager.jsm:700 < AddonManagerInternal.startup()@resource://gre/modules/AddonManager.jsm:870 < this.AddonManagerPrivate.startup()@resource://gre/modules/AddonManager.jsm:3033 < amManager.prototype.observe()@resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1677: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1492944492505   Marionette  INFO    Listening on port 50231
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2585: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
Apr 23, 2017 4:18:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
149294489305壁虎河信息监听127.0.0.1:12059
149294489973 geckodriver::木偶网信息启动浏览器\\?\C:\Program Files(x86)\Mozilla Firefox\Firefox.exe,带参数[“-marionette”]
149294491445 addons.manager错误启动失败:[异常…”组件返回失败代码:0x80070057(NS错误非法值)[nsfile.create]“nsresult:“0x80070057(NS错误非法值)”位置:“JS帧::resource://gre/modules/FileUtils.jsm ::FileUtils_getDir::第70行“数据:否]堆栈跟踪:FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 
请帮忙

谢谢,
Ashish Jain

请使用“驱动程序.退出”而不是“驱动程序.关闭”重试


关于“Javascript错误(AddonManager)”,我还在想办法解决它,如果有人知道解决方法,请与我们分享:)

你的Firefox版本是什么

有时问题是安装的FireFox版本和geckodriver版本之间的不兼容

关于“Javascript错误(AddonManager)”。。。我今天几乎发疯了,因为所有的组件都是在上周内逐步安装的,最后我解决了这个问题。 以下是解决方案和说明: geckodriver v.0.16.0“仅与Selenium 3.4及更高版本兼容”(如其页面所述)。 一周前,selenium 3.3.1是最后一个版本。截至4月21日,selenium3.4.0已发布。
我不得不从头开始重新创建项目,重新添加Selenium罐。由于某些原因,在旧项目上简单地替换它们并没有起到作用。

请尝试下面的代码

String Firefoxdriverpath="C://Users//Ashish//Downloads//geckodriver-v0.16.0-win64//geckodriver.exe";
System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);  
driver.close(); 

请告诉我这是否有效。

我看不到您的代码中有任何重大错误。但您需要遵循以下特定准则:

在声明
字符串Firefoxdriverpath
时,您需要使用单前斜杠,即“/”

e、 g.
String Firefoxdriverpath=“C:/Utility/BrowserDrivers/geckodriver.exe”

或者您需要避开背面的斜线,即“\\”

e、 g.
String Firefoxdriverpath=“C:\\Utility\\BrowserDrivers\\geckodriver.exe”

让我知道这是否适用于您。

我也有同样的问题。
帮助的是使用
driver.quit()而不是
driver.close()

我也遇到过类似的问题,但最终还是通过下面这个为selenium 3.4功能更改的小代码解决了-

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", false); // true gives that Javascript error (AddonManager is not initialized)

使用Firefox版本时出现此错误:45.9.0;Selenium 3.4.0和Gecko驱动程序:16.1

解决方案:降级至gecko 16.0并使用: System.setProperty(“webdriver.firefox.marionete”,“Path”)


希望这有帮助。

您使用的gecko驱动程序版本是什么?gecko驱动程序版本geckodriver-v0.16.0-Win64查看我的答案并更新状态。谢谢。我删除了旧项目,重新创建了新项目,并添加了jar文件,仍然显示这个错误。嗨,今天早上我在配置企业计算机时再次遇到它。在这里,从[link]()切换到geckodrive v.0.15.0是有效的。让我知道它是否对您有效。只需通过[link](),在更改的部分中有几点。不确定是否有帮助:1)SendKeysParameters(用于元素Send Keys和Send Alert Text命令)已更新为字符串文本字段。2) 默认情况下禁用Firefox中的Flash和插件容器,这将有助于缓解许多用户在删除带有driver.quit的会话时报告的“Firefox插件容器已停止编写”问题,没有登录,它正在退出浏览器。不,它仍然是相同的。它将收到相同的错误,firefox也不是closing@AshishJain-请下载geckodriver的旧版本以检查测试。这可能是由于mozilla和geckodriver之间的兼容性。还可以尝试改变壁虎河的保存位置。在我的机器里工作得很好。