Selenium启动新的浏览器窗口然后抛出UnreachableBrowserException

时间:2017-06-05 16:36:54

标签: java selenium firefox

我正在尝试设置一个新的Selenium项目,并且无法使思考工作正常。我的环境:

OSX      : 10.12.4
Java     : 1.8.0_121
Selenium : 3.4.0
Gecko    : 0.16.1      ( located at /opt/garbage/geckodriver and on path )
Firefox  : 53.0.3

Java代码

System.setProperty("webdriver.gecko.driver", "/opt/garbage/geckodriver");
System.setProperty("webdriver.firefox.marionette", "/opt/garbage/geckodriver");

WebDriver driver = new FirefoxDriver();  <--

driver.get("https://www.google.com");

在此示例中,第4行将打开一个新的Firefox浏览器窗口,但几秒钟后会抛出以下堆栈:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'myhostname.corp', ip: '10.99.99.99', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.4', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at com.example.TestClass.testMethod(TestClass.java:19)

失败的跑步中的StdErr:

2017-06-05 12:24:08.483 firefox-bin[35514:5688975] IMKInputSession presentFunctionRowItemTextInputViewWithEndpoint:completionHandler: : [self textInputContext]=0x12cd37a00 *NO* NSRemoteViewController to client, NSError=Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 0" UserInfo={NSDebugDescription=connection from pid 0}, com.apple.inputmethod.EmojiFunctionRowItem
2017-06-05 12:24:08.891 firefox-bin[35514:5688975] IMKInputSession presentFunctionRowItemTextInputViewWithEndpoint:completionHandler: : [self textInputContext]=0x12cd37a00 *NO* NSRemoteViewController to client, NSError=Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 0" UserInfo={NSDebugDescription=connection from pid 0}, com.apple.inputmethod.EmojiFunctionRowItem
2017-06-05 12:24:09.248 plugin-container[35516:5689303] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x983b, name = 'com.apple.tsm.portname'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2017-06-05 12:24:09.248 plugin-container[35516:5689303] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9b03, name = 'com.apple.CFPasteboardClient'
See /usr/include/servers/bootstrap_defs.h for the error codes.

我可能会错误配置什么?

修改

我也尝试过使用以下功能 - 无需更改

DesiredCapabilities caps = new FirefoxOptions()//
        .setProfile(new FirefoxProfile())//
        .addTo(DesiredCapabilities.firefox());

WebDriver driver = new FirefoxDriver( caps );  <--

1 个答案:

答案 0 :(得分:0)

此代码对我有用

System.setProperty("webdriver.gecko.driver", "/opt/garbage/geckodriver.exe");
`WebDriver driver = new FirefoxDriver();`  <--
 driver.get("https://www.google.com");

我的配置:

Selenium:3.4.0

壁虎:0.16.1
火狐:53.0.3