org.openqa.selenium.SessionNotCreatedException:无法在Mac中创建新的远程会话

时间:2017-03-10 19:44:30

标签: java macos selenium firefox

我对selenium很新,并尝试使用以下java代码调用Firefox浏览器。

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

public class google {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.gecko.driver", "/Users/gowtham/Desktop/Selenium/geckodriver");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://google.com");
        Thread.sleep(1000);
        driver.quit();
    }
}

当我运行上面的代码时,我的控制台上出现以下异常。

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@7d70d1b1, version=, platform=ANY, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@2a742aa2}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'system', ip: 'fe80:0:0:0:2acf:e9ff:fe19:261%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', 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:293)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:272)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:267)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:263)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:122)
    at HelloWorls.google.main(google.java:11)

我的机器上安装了firefox v52.0。

请分享您对此问题的看法。

1 个答案:

答案 0 :(得分:2)

到目前为止我无法添加评论,因此请在此处解决此问题。 实际上,gecko驱动程序版本需要降级。 对于那些使用'bonigarcia-webdrivermanager'的人,在实例化FirefoxDriver之前显式添加驱动程序版本:

FirefoxDriverManager.getInstance().setup("0.14.0");
相关问题