You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Selenium至4.8.3后抛出NoClassDefFoundError问题求助

解决Selenium 4.8.3升级后ElementNotVisibleException找不到的问题

问题根源

Selenium 4.x版本开始移除了ElementNotVisibleException这个异常类,它被合并到ElementNotInteractableException中。升级后代码若仍引用旧异常类,就会触发NoClassDefFoundError。

具体解决步骤

  • 替换异常引用:将代码中所有org.openqa.selenium.ElementNotVisibleException替换为org.openqa.selenium.ElementNotInteractableException。
  • 清理IDE缓存:在IntelliJ中操作:
    1. 点击菜单栏File → Invalidate Caches...
    2. 勾选Invalidate and Restart,重启IDE
  • 统一依赖版本:确保pom.xml(Maven)或build.gradle(Gradle)中Selenium依赖版本统一为4.8.3,避免混合旧版本:
    • Maven示例:
      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>4.8.3</version>
      </dependency>
      
    • Gradle示例:
      implementation 'org.seleniumhq.selenium:selenium-java:4.8.3'
      
  • 同步依赖:点击IntelliJ中Maven/Gradle工具窗口的Reload All Maven Projects或Refresh Gradle Project按钮,确保依赖正确下载。

关于旧版本403错误说明

旧版本Selenium出现java.io.IOException: Invalid Status code=403 text=Forbidden,多因浏览器驱动与浏览器版本不兼容,或旧版本不支持最新浏览器安全协议。升级到4.8.3后,只要保证浏览器驱动和本地浏览器版本匹配即可解决,也可使用Selenium的WebDriverManager自动管理驱动版本,省去手动匹配的麻烦。

内容的提问来源于stack exchange,提问作者lalexa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 12:12:04