无法关闭 selenium webdriver 对象 4.11.0 和 4.12.1

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

每当我尝试关闭网络驱动程序时,它都会抛出错误:“java.net.SocketException:连接重置”。 代码片段、控制台日志和 pom.xml 可通过以下链接获取:https://gist.github.com/SambathKumar/7a7c6c9659ae0fa4b3cadc0c7f61d76f

问题是什么以及如何解决这个问题?

Orangehrm.java

package sam.test;

import java.time.Duration;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Orangehrm {

    public static void main(String[] args) throws InterruptedException {

        ChromeOptions co=new ChromeOptions();
        WebDriver wd=new ChromeDriver(co);
        final int SLEEPSEC=3000;
        try {
            System.out.println("Before launch orange hrm");
            wd.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
            System.out.println("After launch orange hrm");
            wd.manage().window().maximize();
            wd.manage().timeouts().implicitlyWait(Duration.ofSeconds(SLEEPSEC));
            wd.findElement(By.cssSelector("input[name='username']")).clear();
            System.out.println("After clearing the username field");
            wd.findElement(By.cssSelector("input[name='username']")).sendKeys("Admin");
            System.out.println("After entering the username as Admin");
            wd.findElement(By.cssSelector("input[name='password']")).clear();
            System.out.println("After clearing the password field");
            wd.findElement(By.cssSelector("input[name='password']")).sendKeys("admin123");
            System.out.println("After entering the password as admin123");
            wd.findElement(By.cssSelector("button[type='submit']")).submit();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            System.out.println("before close");
            //Thread.sleep(SLEEPSEC);
            wd.close();
            System.out.println("before quit");
            wd.quit();
            System.out.println("after quit");
        }

    }
}
    

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.sam</groupId>
  <artifactId>sam.test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>test</name>
  
  <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.12.1</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<!--        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.11.0</version>
        </dependency>-->

  </dependencies>


</project>

控制台.logs

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.
Oct 02, 2023 10:51:13 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 117, so returning the closest version found: 116
Before launch orange hrm
After launch orange hrm
After clearing the username field
After entering the username as Admin
After clearing the password field
After entering the password as admin123
before close
Oct 02, 2023 10:51:16 PM 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:394)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:254)
    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:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    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:833)

before quit
after quit
java windows selenium-webdriver webdriver maven-3
1个回答
0
投票

我无法评论。所以我把它放在答案中。

我在 Chrome 117.0.5938.150 上使用 ChromeDriver 尝试了您的代码 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/117.0.5938.92/win64/chromedriver-win64.zip 一切都好。

您有哪些版本?

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