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

升级Java至17适配Spring Boot 3后Selenium测试遇NoSuchMethodError求助

问题解决:Selenide与Selenium版本不兼容导致的NoSuchMethodError

问题原因

你遇到的java.lang.NoSuchMethodError确实是Selenide与Selenium版本不匹配造成的。Selenide 6.11.2依赖的Selenium版本高于你当前使用的4.8.0,org.openqa.selenium.chrome.ChromeOptions.mergeInOptionsFromCaps方法是在更高版本的Selenium中新增的,4.8.0版本中不存在该方法,因此调用时触发错误。

解决方案

方案1:升级Selenium到兼容版本

根据Selenide官方兼容规则,6.11.2需要搭配Selenium 4.10.0及以上版本。修改pom.xml中的Selenium版本:

<properties>
    <selenium.version>4.10.0</selenium.version>
    <!-- 其他属性保持不变 -->
</properties>

方案2:降级Selenide到适配版本

如果不想升级Selenium,可将Selenide降级到6.9.1(该版本兼容Selenium 4.8.0):

<dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>selenide</artifactId>
    <version>6.9.1</version>
</dependency>

额外优化建议

selenium-java依赖已包含selenium-api、selenium-chrome-driver、selenium-remote-driver,删除这些重复的子依赖,避免潜在的版本冲突:

<!-- 保留这一个即可,删除其他Selenium子依赖 -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>${selenium.version}</version>
</dependency>

补充说明

你之前遇到的java.lang.NoClassDefFoundError: io/opentelemetry/sdk/metrics/exemplar/ExemplarFilter,是因为Selenium 4.1.1依赖的OpenTelemetry版本与Spring Boot 3的依赖冲突,升级到4.8.0解决了该问题,但由于Selenide版本未同步匹配,引发了新的版本兼容问题,统一依赖版本是解决这类问题的核心。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 05:24:20