SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.76k stars 8.02k forks source link

[🐛 Bug]: The problem of [java.lang.IllegalArgumentException: Unknown HttpClient factory jdk-http-client] has appeared again. #14205

Closed studyJavaForLive closed 5 days ago

studyJavaForLive commented 5 days ago

What happened?

I have a java project with dependencies

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>4.22.0</version>
</dependency>

Environment

JDK17
Windows 11
Edgebrowser: 106.0.1370.86

I packaged it using the following method to avoid dependency conflicts in another project.

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
  <execution>
    <phase>package</phase>
    <goals>
      <goal>shade</goal>
    </goals>
    <configuration>
      <relocations>
        <relocation>
          <pattern>org.openqa.selenium</pattern>
          <shadedPattern>link-download.org.openqa.selenium</shadedPattern>
        </relocation>
      </relocations>
    </configuration>
  </execution>
</executions>

My main function to excute.

    public void downloadFileThroughUrl() throws InterruptedException {
    System.setProperty("webdriver.edge.driver", System.getProperty("user.dir") + File.separator + "MicrosoftWebDriver.exe");

    EdgeOptions edgeOptions = new EdgeOptions();
    edgeOptions.addArguments("--headless");

    Map<String, Object> settings = new HashMap<>();
    settings.put("download.default_directory", System.getProperty("user.dir"));
    settings.put("plugins.always_open_pdf_externally", true);
    settings.put("download.prompt_for_download",false);
    settings.put("profile.default_content_settings.popups",0);
    settings.put("safebrowsing.enabled",true);

    WebDriver driver = null;
    try {
        edgeOptions.setExperimentalOption("prefs",settings);
        driver = new EdgeDriver(edgeOptions);
        driver.get("your valid download link");
        Thread.sleep(10000);
        System.out.println("Download successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if(driver != null){
            driver.quit();
        }
    }
}

Jar file link-download-1.0-SNAPSHOT.zip

How can we reproduce the issue?

In a new project, depending on this JAR file, and calling it using the following method:
    DownloadFileByLink downloadFileByLink = new DownloadFileByLink();
    downloadFileByLink.downloadFileThroughUrl();
Will appear [[java.lang.IllegalArgumentException: Unknown HttpClient factory jdk-http-client] when creating new driver.

Relevant log output

Caused by: java.lang.IllegalArgumentException: Unknown HttpClient factory jdk-http-client
    at link-download.org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57)
    at link-download.org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:74)
    at link-download.org.openqa.selenium.remote.HttpCommandExecutor$DefaultClientFactoryHolder.<clinit>(HttpCommandExecutor.java:56)
    ... 17 more

Operating System

Windows 11

Selenium version

4.22.0

What are the browser(s) and version(s) where you see this issue?

Edgebrowser: 106.0.1370.86

What are the browser driver(s) and version(s) where you see this issue?

EdgeDriver

Are you using Selenium Grid?

NO

github-actions[bot] commented 5 days ago

@studyJavaForLive, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

studyJavaForLive commented 5 days ago

I tried to solve the problem using the following link, but unfortunately, it was not successful. https://www.selenium.dev/blog/2022/using-java11-httpclient/

diemol commented 5 days ago

Instructions on repackaging Selenium are out of the scope as an issue. You can ask questions using the links below. You can also join the Slack channel and ask for help from the folks who are there.

github-actions[bot] commented 5 days ago

💬 Please ask questions at: