Selenium:未知的 HttpClient 工厂 netty

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

使用 ProcessBuilder (java) 执行 selenium 代码时,收到以下错误消息:

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:62)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:87)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:80)
at org.openqa.selenium.chromium.ChromiumDriverCommandExecutor.<init>(ChromiumDriverCommandExecutor.java:35)
at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
at SeleniumProto.main(SeleniumProto.java:7)
Caused by: java.lang.IllegalArgumentException: Unknown HttpClient factory netty
  at org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57)
  at org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:73)
  at org.openqa.selenium.remote.HttpCommandExecutor$DefaultClientFactoryHolder.<clinit>(HttpCommandExecutor.java:58)
  ... 9 more

Process finished with exit code 1

硒代码如下:

   import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumProto {
    public SeleniumProto() {
    }

    public static void main(String[] var0) {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\OneDrive\\Documents\\chromedriver.exe");
        ChromeDriver var1 = new ChromeDriver();
        var1.get("https://www.twitter.com");
    }
}

网上关于如何解决此问题的答案并不多。

java selenium processbuilder
2个回答
0
投票

看起来像是与 selenium 版本或错误的 webdriver 版本有关的问题。试试这个:

    public static void main(String[] args) {
        WebDriverManager.chromedriver().setup();
        ChromeDriver driver = new ChromeDriver();
        driver.get("https://www.twitter.com");
    }

使用以下依赖项:

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.6.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.1</version>
        </dependency>


0
投票

我遇到了相同或类似的问题。我将

selenium-java
依赖项从 4.5 更新到最新的 4.18.1,然后立即出现此错误以及其他运行时错误。这很可能是由于
selenium-java
周围不兼容造成的。 当我将版本撤回到 4.5 时,错误就消失了。

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