Home > Back-end >  Selenium Connection Reset: Unable to find an exact match for CDP version 96, so returning the closes
Selenium Connection Reset: Unable to find an exact match for CDP version 96, so returning the closes

Time:11-21

Stack Trace:

Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 58050
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Nov 20, 2021 9:34:48 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Nov 20, 2021 9:34:49 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 96, so returning the closest version found: 95
Nov 20, 2021 9:34:49 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 96 of 95
Nov 20, 2021 9:36:34 AM org.openqa.selenium.remote.http.WebSocket$Listener one rror
WARNING: Connection reset
java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    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:831)

I am making a java selenium bot and when I start the bot it says connection reset after the last line of the code

I get this error even though my

  • Chrome version = 96
  • Driver version = 96

Please help

Here is the code:

public static void main(String[] args) throws InterruptedException {
        //region GUI
        int loginTimeOutDuration = 100000;
        int chatLoadingDelay = 1000;
        String serverID = "707324806856572949";
        String message = "Hi!";
        //endregion

        System.setProperty
                ("webdriver.chrome.driver","C:\\\\Users\\\\~~~~~\\\\Downloads\\\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        String baseUrl = "https://discord.com/channels/"   serverID   "/";

        driver.get(baseUrl);
        Thread.sleep(loginTimeOutDuration);
        WebElement element = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[2]/div/div/div/"  
                "div/div[2]/div[2]/div/aside/div/div/div[2]/div/div[2]/div[1]"));

        Actions actions = new Actions(driver);
        actions.contextClick(element).perform();
        driver.findElement(By.xpath("/html/body/div[1]/div[5]/div/div/div/div[1]/div[2]")).click();

        driver.close();
    }

CodePudding user response:

This SocketException occurs on the server side when the client closed the socket connection before the response could be returned over the socket. For example, by quitting the browser before the reponse was retrieved.

discord.com uses Websocket communication, when you connect, wss://remote-auth-gateway.discord.gg/?v=1 Waiting for certification. (socket is alive)

Maybe driver.close() closed the the socket.

CodePudding user response:

This error message...

Nov 20, 2021 9:34:49 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 96, so returning the closest version found: 95
Nov 20, 2021 9:34:49 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 96 of 95
Nov 20, 2021 9:36:34 AM org.openqa.selenium.remote.http.WebSocket$Listener one rror
WARNING: Connection reset
java.net.SocketException: Connection reset

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session and java.net.SocketException: Connection reset occured.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • Though you are using chromedriver=96.0
  • Possibly you are using Selenium v4.0.0 which:
  • Supported CDP versions: 85, 93, 94, 95

Hence, you see:

WARNING: Unable to find an exact match for CDP version 96, so returning the closest version found: 95

Solution

Ensure that:

  • Selenium is upgraded to current v4.1.0 where:
  • Supported CDP versions: 85, 94, 95, 96
  • Related