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

如何解决“无法访问org.openqa.selenium.internal.WrapsElement”问题?

解决Selenium 4.9.0编译时找不到WrapsDriver/WrapsElement的问题

问题分析

  1. Selenium 4.x 已移除org.openqa.selenium.internal包下的WrapsDriver和WrapsElement类,相关类已迁移至org.openqa.selenium.support包。
  2. 代码中调用的getNgElement()是ngWebDriver(用于Angular应用自动化)的API,旧版本的ngWebDriver依赖Selenium旧版本的internal包类,和Selenium 4.9.0不兼容。
  3. 无需单独引入selenium-api依赖,selenium-java已经包含该依赖,重复引入可能引发依赖冲突。

解决步骤

  • 移除pom.xml中单独的selenium-api依赖,只保留selenium-java:
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.9.0</version>
</dependency>
  • 更新ngWebDriver到兼容Selenium 4.x的版本,比如使用适配的稳定版:
<dependency>
    <groupId>com.github.automatedowl</groupId>
    <artifactId>ng-web-driver</artifactId>
    <version>1.1.1</version>
</dependency>
  • 清理Maven依赖并重新编译:
mvn clean install -U

额外说明

IDE能找到类是因为IDE可能加载了旧版本的Selenium依赖(比如ngWebDriver自带的旧Selenium包),但Maven编译时依赖解析出现冲突,导致找不到正确的类文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 21:48:14