首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用GeckoDriver启动火狐

无法使用GeckoDriver启动火狐
EN

Stack Overflow用户
提问于 2017-02-06 20:15:43
回答 3查看 1.7K关注 0票数 0

我正在我的Mac和Selenium 3.0.1上运行Firefox 51,无论我尝试什么,我都无法让Firefox使用我的selenium代码。我将GeckoDriver添加到/usr/local/bin 中,添加了系统属性行,但它始终获得connection refused.。这是我的代码:

代码语言:javascript
运行
复制
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.FirefoxDriverManager;

public WebDriver getDriver() throws MalformedURLException {     
    FirefoxDriverManager.getInstance().setup();
    System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
    driver = new FirefoxDriver();
    // Tests here
}

以下是错误日志:

代码语言:javascript
运行
复制
Usage:
    /usr/local/bin/geckodriver [OPTIONS]
/usr/local/bin/geckodriver: Unknown option --port=30325
Feb 06, 2017 1:59:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
FAILED CONFIGURATION: @BeforeTest Before
org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:30325 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'Kevins-MacBook-Pro.local', ip: '192.168.0.26', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
    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:238)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
    at com.kirklands.automation.ecom.Base.getDriver(Base.java:29)
    at com.kirklands.automation.ecom.tests.TestBase.Before(TestBase.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.beforeRun(TestRunner.java:641)
    at org.testng.TestRunner.run(TestRunner.java:609)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:30325 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:142)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:88)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:108)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    ... 32 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
    ... 47 more

SKIPPED CONFIGURATION: @AfterTest After

Chrome运行得很好(如果我使用ChromeDriverManager.的话,这也在ChromeDriverManager.上),这一点都不值钱。所以我不知道这里发生了什么。

EN

回答 3

Stack Overflow用户

发布于 2017-02-20 14:25:51

我认为Geckodriver路径才是问题所在。

尝试指定如下所示。

代码语言:javascript
运行
复制
System.setProperty("webdriver.gecko.driver","D:\\Jar's\\geckodriver-v0.11.1-win64\\geckodriver.exe");

如果有用请告诉我。

票数 0
EN

Stack Overflow用户

发布于 2017-03-13 21:40:59

最后我发现了问题,检查一下是否有webdriver v15?因为linux只存在64位,所以缺少32位,所以如果您有32位,它将无法工作。我安装了版本14,32位,它运行得很好。

票数 0
EN

Stack Overflow用户

发布于 2017-04-24 08:52:45

尝尝这个

代码语言:javascript
运行
复制
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");          
driver = new FirefoxDriver();

不要忘记下载geckodriver并将其放在您想要的路径中。我直接把它放在C:\驱动器里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42076497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档