gpt4 book ai didi

java - Selenium 在 Java Web 项目上运行时抛出 "NoSuchMethodError"

转载 作者:行者123 更新时间:2023-11-30 02:24:33 24 4
gpt4 key购买 nike

我用 Java 中的 Selenium 库编写了一些逻辑来执行一些简单的 Web 抓取(该逻辑对于这个问题并不重要),这些逻辑在我的 Java Web 项目中从简单测试文件的 main() 函数运行时有效。当我尝试移动此逻辑代码,甚至只是从实际的 servlet 或 JSP 文件调用此代码时,服务器会因以下异常而崩溃:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
at scraping.OneCardScraper.<init>(OneCardScraper.java:41)
at org.apache.jsp.Home_jsp._jspService(Home_jsp.java:212)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

错误指向这一行:driver = new FirefoxDriver();

我在这里做错了什么?

我很困惑为什么 Selenium 依赖项可能在 Web 平台上遇到问题,而不是在典型的测试运行上遇到问题,因为依赖项应该继续存在。

我已经尝试过:

  • 多次重新启动 IDE
  • 清洁、建筑等
  • 将整个项目迁移到基于 Maven 的依赖系统
  • 更改 selenium 中的浏览器类型(PhantomJS、HTMLUnit、Chrome、FireFox)
  • 将 Webdriver 位置变量添加到 web.xml 上下文参数

我正在使用:

  • Netbeans 8.2
  • Java EE 7
  • Selenium 3.5.3

最佳答案

这基本上意味着 Guava 依赖项存在冲突。

您可能想检查这个 Selenium commit还有这些 Guava 21 release notes 。最新的 Selenium 版本需要 Guava 21+,而 Guava 21+ 需要 Java 8。因此,您必须降级 Selenium 或升级 Java 以避免此类问题。

关于java - Selenium 在 Java Web 项目上运行时抛出 "NoSuchMethodError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45965801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com