如何帮助这个org.openqa.selenium.remote.http.WebSocket$Listener onError?

问题描述 投票:0回答:4

所以,我开始在网络上运行基本的打开chrome,selenium程序。

导入 org.openqa.selenium.chrome.*;

公开课测试{

static {
    System.setProperty("webdriver.chrome.driver","./driver/chromedriver.exe");
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    ChromeDriver driver= new ChromeDriver();
    driver.close();

}

}

出现以下错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 102.0.5005.61 (0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs/branch-heads/5005@{#819}) on port 50054
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jun 08, 2022 11:17:57 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Jun 08, 2022 11:17:57 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 102, so returning the closest version found: 101
Jun 08, 2022 11:17:57 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 102 of 101
Jun 08, 2022 11:17:58 AM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:345)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:376)
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:258)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:830)
java selenium-webdriver
4个回答
5
投票

您应该尝试一下为 chrome 选项添加的这个参数:

.addArguments("--remote-allow-origins=*")

3
投票

在其中使用此代码....

ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");

WebDriver driver = new ChromeDriver(options);

0
投票

您的主要问题是您正在使用的binaries版本之间的

不兼容
,如下所示:

您已下载并使用

chromedriver=102.0
,启动成功。 但你还在用
chrome=101

ChromeDriver v102的发行说明明确提到了以下内容:

    支持Chrome版本102

解决方案

解决方案 确保:

Chrome 浏览器已更新至当前 chrome=102


0
投票
代替 driver.close();使用 driver().quit();关闭浏览器时应该可以解决

© www.soinside.com 2019 - 2024. All rights reserved.