SeleniumHQ / selenium

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

[🐛 Bug]: Java17, input.readArray method not found #13443

Closed ixiaofu closed 9 months ago

ixiaofu commented 9 months ago

What happened?

In Java17, using selenium devtools, it was found that the input.readArray method does not exist.

image

How can we reproduce the issue?

1. Create java workspace, use java 17.0.9
2. Use Selenium 4.16.1
3. Create ChromeDevTools
3.1 this.chromeDevTools.createSession();
3.2 this.chromeDevTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
3.3 this.chromeDriver.get("https://www.domain.com");
4. Run java workspace
5. java.lang.NoSuchMethodError: 'java.util.function.Function org.openqa.selenium.devtools.ConverterFunctions.map(java.lang.String, java.util.function.Function)'

Relevant log output

INFO 37392 --- [  restartedMain] com.yyyyyyy.xxxxxxx.xxxxxxxApplication       : Starting xxxxxxxApplication using Java 17.0.9 with PID 37392 (/Users/yyyyyyy/custom/java/xxxxxxx/build/classes/java/main started by yyyyyyy in /Users/yyyyyyy/custom/java/xxxxxxx)
 INFO 37392 --- [  restartedMain] com.yyyyyyy.xxxxxxx.xxxxxxxApplication       : No active profile set, falling back to 1 default profile: "default"
 INFO 37392 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
 INFO 37392 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
 INFO 37392 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with ports 18443 (https), 18080 (http)
 INFO 37392 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
 INFO 37392 --- [  restartedMain] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.17]
 INFO 37392 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 INFO 37392 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 487 ms
 INFO 37392 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
 INFO 37392 --- [  restartedMain] o.a.t.util.net.NioEndpoint.certificate   : Connector [https-jsse-nio-18443], TLS virtual host [_default_], certificate type [UNDEFINED] configured from keystore [/Users/yyyyyyy/.keystore] using alias [1] with trust store [null]
 INFO 37392 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on ports 18443 (https), 18080 (http) with context path ''
 INFO 37392 --- [  restartedMain] com.yyyyyyy.xxxxxxx.xxxxxxxApplication       : Started xxxxxxxApplication in 1.059 seconds (process running for 1.321)
 INFO 37392 --- [io-18080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
 INFO 37392 --- [io-18080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
 INFO 37392 --- [io-18080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
ERROR 37392 --- [io-18080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: java.lang.NoSuchMethodError: 'java.util.function.Function org.openqa.selenium.devtools.ConverterFunctions.map(java.lang.String, java.util.function.Function)'] with root cause

java.lang.NoSuchMethodError: 'java.util.function.Function org.openqa.selenium.devtools.ConverterFunctions.map(java.lang.String, java.util.function.Function)'
  at org.openqa.selenium.devtools.v120.target.Target.getTargets(Target.java:153) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.v120.v120Target.getTargets(v120Target.java:55) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.findTarget(DevTools.java:171) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:131) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:117) ~[selenium-remote-driver-4.14.1.jar:na]
  at com.yyyyyyy.xxxxxxx.utils.selenimu.LoginManager.initDriver(LoginManager.java:75) ~[main/:na]
  at com.yyyyyyy.xxxxxxx.utils.selenimu.LoginManager.doLogin(LoginManager.java:127) ~[main/:na]
  at com.yyyyyyy.xxxxxxx.controller.UserController.login(UserController.java:25) ~[main/:na]
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
  at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
  at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:262) ~[spring-web-6.1.2.jar:6.1.2]
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:190) ~[spring-web-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:917) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:829) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) ~[tomcat-embed-core-10.1.17.jar:6.0]
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.1.2.jar:6.1.2]
  at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.17.jar:6.0]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.1.2.jar:6.1.2]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.2.jar:6.1.2]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.1.2.jar:6.1.2]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.2.jar:6.1.2]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.1.2.jar:6.1.2]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.2.jar:6.1.2]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:597) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.17.jar:10.1.17]
  at java.base/java.lang.Thread.run(Thread.java:842) ~[na:na]

Operating System

MacOS 14.0

Selenium version

4.16.1

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

Google Chrome 120.0.6099.216 arm

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

selenium-chrome-driver-4.14.1.jar

Are you using Selenium Grid?

No response

github-actions[bot] commented 9 months ago

@ixiaofu, 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!

github-actions[bot] commented 9 months ago

Hi, @ixiaofu. Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

ixiaofu commented 9 months ago
package com.xxx;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v120.network.Network;

class Test {

  private WebDriver chromeDriver;

  private DevTools chromeDevTools;

  private WebDriver getDriver() {
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
      return driver;
  }

  private boolean initDriver() {
      if (this.chromeDriver == null) {
          this.chromeDriver = getDriver();
      }
      if (this.chromeDevTools == null) {
          this.chromeDevTools = ((ChromeDriver) this.chromeDriver).getDevTools();
          this.chromeDevTools.createSession();
          this.chromeDevTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
      }
      return this.chromeDriver != null && this.chromeDevTools != null;
  }

  public Test() {
    initDriver();
  }

}
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.1'
    id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.xxxxx'
version = '1.0.0'

java {
    sourceCompatibility = '17'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.seleniumhq.selenium:selenium-java:4.16.1'
}

tasks.named('test') {
    useJUnitPlatform()
}
joerg1985 commented 9 months ago
java.lang.NoSuchMethodError: 'java.util.function.Function org.openqa.selenium.devtools.ConverterFunctions.map(java.lang.String, java.util.function.Function)'
  at org.openqa.selenium.devtools.v120.target.Target.getTargets(Target.java:153) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.v120.v120Target.getTargets(v120Target.java:55) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.findTarget(DevTools.java:171) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:131) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:117) ~[selenium-remote-driver-4.14.1.jar:na]

There are mixed versions (4.14.1 and 4.16.1) on your classpath, this is the reason for the failure.

ixiaofu commented 9 months ago
java.lang.NoSuchMethodError: 'java.util.function.Function org.openqa.selenium.devtools.ConverterFunctions.map(java.lang.String, java.util.function.Function)'
  at org.openqa.selenium.devtools.v120.target.Target.getTargets(Target.java:153) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.v120.v120Target.getTargets(v120Target.java:55) ~[selenium-devtools-v120-4.16.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.findTarget(DevTools.java:171) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:131) ~[selenium-remote-driver-4.14.1.jar:na]
  at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:117) ~[selenium-remote-driver-4.14.1.jar:na]

There are mixed versions (4.14.1 and 4.16.1) on your classpath, this is the reason for the failure.

Thank you very much. After investigation, it was found that after importing Springboot into the project, the Selenium version was automatically downgraded under Gradle management.

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.