Java Selenium 3.0 Firefx 驱动程序因 org.openqa.selenium.SessionNotCreatedException 失败:无法创建新的远程会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40106844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:24:23  来源:igfitidea点击:

Selenium 3.0 Firefx Driver fails with org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session

javaseleniumfirefoxselenium-firefoxdrivergeckodriver

提问by KingArasan

Selenium 3.0 Firefx Driver fails with org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session.

Selenium 3.0 Firefx 驱动程序因 org.openqa.selenium.SessionNotCreatedException 失败:无法创建新的远程会话。

System.setProperty("webdriver.gecko.driver", "..<Path>../geckodriver.exe");
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);


Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@23aa363a, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@23aa363a, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'D202540', ip: '10.22.19.193', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:259)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:247)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:242)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:135)

回答by Immers Cherub

You need to download geckodriver. And then set

您需要下载 geckodriver。然后设置

System.setProperty("webdriver.gecko.driver", "path\to\geckodriver.exe")

Check this link.

检查此链接

回答by mosaad

I had the same problem and fixed it with this. It seems it could not find the firefox binary

我遇到了同样的问题并用这个修复了它。似乎找不到firefox二进制文件

capabilities.setCapability("firefox_binary","C:\Program Files\Mozilla Firefox\firefox.exe");

回答by Dazz

Same problem here. It was solved opening Eclipse/Netbeans with admin privileges.

同样的问题在这里。以管理员权限打开 Eclipse/Netbeans 已解决。

回答by nexoma

This worked (linux mint, opensuse thumbleweed, win7) with

这工作(linux mint,opensuse thumbleweed,win7)与

libraryDependencies += "org.seleniumhq.selenium" % "selenium-firefox-driver" % "3.0.1"

geckodriver.exe -V geckodriver 0.13.0

libraryDependencies += "org.seleniumhq.selenium" % "selenium-firefox-driver" % "3.0.1"

geckodriver.exe -V geckodriver 0.13.0

if (System.getProperty("os.name").toLowerCase().contains("linux")) {
  println("загружены настройки os.name=linux")
  System.setProperty("webdriver.chrome.driver", "bin/chromedriver")
  System.setProperty("webdriver.gecko.driver", "bin/geckodriver")

}else{
  System.setProperty("webdriver.chrome.driver", "bin\chromedriver.exe")
  System.setProperty("webdriver.gecko.driver", "bin\geckodriver.exe")
  System.setProperty("webdriver.ie.driver", "bin\IEDriverServer.exe")
  System.setProperty("webdriver.edge.driver", "C:\Program Files (x86)\Microsoft Web Driver\MicrosoftWebDriver.exe")
  System.setProperty("webdriver.opera.driver", "c:\XXX\operadriver.exe")

  System.setProperty("webdriver.opera.path","""C:\Users\user\AppData\Local\Programs\Opera""")
  System.setProperty("webdriver.opera.binary","""C:\Users\user\AppData\Local\Programs\Opera\launcher.exe""")
  //
}

...

...

      case
        "firefox" => {
        println(" подгружаем Веб-драйвер: geckodriver")
        //iniprofile = new ProfilesIni()
        //ffprofile = iniprofile.getProfile("default")
        dc = DesiredCapabilities.firefox()
        dc.setCapability("gecko", true) // как выйдет драйвер, так и установить
//        dc.setCapability(FirefoxDriver.PROFILE, ffprofile); //FirefoxDriver.PROFILE = “firefox_profile”;
        remote = new FirefoxDriver(dc)
      }

but, for Remotewebdriver-connection if previous session failed,cancelled or aborted we get error:

但是,对于 Remotewebdriver-connection,如果上一个会话失败、取消或中止,我们会收到错误消息:

[info] XXXX.E011_WebDB6292 *** ABORTED ***
[info]   org.openqa.selenium.SessionNotCreatedException: Session is already started (WARNING: The server did not provide any stacktrace information)
[info] Command duration or timeout: 0 milliseconds
[info] Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
[info] System info: host: 'XXXX', ip: '172.16.4.125', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_11'
[info] Driver info: driver.version: RemoteWebDriver
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

回答by Adonis

I ran into the same problem today, and it appears that not being admin on my laptop is actually an issue. To resolve it

我今天遇到了同样的问题,看来我的笔记本电脑上没有管理员实际上是一个问题。解决它

  • Install in a non admin way Firefox (just need to click on no when Windows ask for privilege elevation)
  • Use the exe path (for my system something like C:\\Users\\MyUserName\\AppData\\Local\\MozillaFirefox\\firefox.exe).

    It actually solved the issue.

  • 以非管理员方式安​​装 Firefox(只需在 Windows 要求提升权限时单击“否”)
  • 使用 exe 路径(对于我的系统,类似于C:\\Users\\MyUserName\\AppData\\Local\\MozillaFirefox\\firefox.exe)。

    它实际上解决了这个问题。

回答by A user

Alternatively if you dont want to download the Gecko driver, you can downgrade the Firefox version to 44.

或者,如果您不想下载 Gecko 驱动程序,您可以将 Firefox 版本降级到 44。

https://support.mozilla.org/t5/Install-and-Update/Install-an-older-version-of-Firefox/ta-p/1564

https://support.mozilla.org/t5/Install-and-Update/Install-an-older-version-of-Firefox/ta-p/1564

回答by Chetan G. Bendre

this issue is solved with geckodriver 0.15 and selenium 3.3 version.

此问题已通过 geckodriver 0.15 和 selenium 3.3 版本解决。