gpt4 book ai didi

java - org.openqa.selenium.WebDriverException : java.net.ConnectException:无法使用 GeckoDriver 和 Selenium 连接到 localhost/0:0:0:0:0:0:0:1:1941

转载 作者:行者123 更新时间:2023-11-30 05:47:24 31 4
gpt4 key购买 nike

我正在尝试使用 Eclipse 编写一个简单的自动化测试,但在设置它时遇到问题。我无法启动 Firefox。我的代码如下,之后是错误堆栈。

代码:

package cucumberTest;

import java.util.concurrent.TimeUnit;

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

public class seleniumTest {

private static WebDriver driver = null;

public static void main(String[] args) {
// TODO Auto-generated method stub

//https://www.toolsqa.com/cucumber/first-cucumber-selenium-java-test/
// new instance of frefox driver
driver = new FirefoxDriver();

//Put a Implicit wait, this means that any search for elements on the page
// could take the time the implicit wait is set for before throwing exception

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//open page
driver.get("http://www.store.demoqa.com");

错误堆栈:这是当我尝试在 ECLIPSE 中运行代码时控制台窗口中显示的内容。

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-P3SB6R8A', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at cucumberTest.seleniumTest.main(seleniumTest.java:18)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
... 6 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
... 28 more

请问有人可以帮我找出问题所在吗?

最佳答案

此错误消息...

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-P3SB6R8A', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
.
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941

...意味着您的程序无法启动/生成新的 GeckoDriver 服务。

使用Selenium v​​3.xGeckoDriverFirefox启动新的GeckoDriver服务并< em>Firefox 浏览器 session ,您需要传递Keywebdriver.gecko.driver以及设置为Value>GeckoDriver 通过 System.setProperty() 行的绝对路径,如下所示:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
driver = new FirefoxDriver();

此外,

  • 您的JDK版本1.8.0_161,这是相当旧的。
  • 您的 Selenium 客户端版本是 v3.141.59
  • 我们未知您的GeckoDriver版本。
  • 我们未知您的Firefox版本。

因此,JDK v8u161Selenium Client v3.141.59 之间存在明显的不匹配。

解决方案

  • JDK 升级到最新级别 JDK 8u202 .
  • 将 GeckoDriver 升级至 GeckoDriver v0.24.0级别。
  • GeckoDriver 存在于指定位置。
  • GeckoDriver 对非 root 用户具有可执行权限。
  • Firefox 版本升级至 Firefox v65.0 级别。
  • 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
  • 如果您的基本网络客户端版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和已发布版本的Web 客户端
  • 重新启动系统
  • 以非 root 用户身份执行测试
  • 始终在 tearDown(){} 方法中调用 driver.quit() 来关闭和销毁 WebDriverWeb Client 优雅地实例化。

关于java - org.openqa.selenium.WebDriverException : java.net.ConnectException:无法使用 GeckoDriver 和 Selenium 连接到 localhost/0:0:0:0:0:0:0:1:1941,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54610588/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com