You need to enable JavaScript to run this app. IDE 2021-03中Selenium可执行Jar失效,DesiredCapabilities类导入报错
优惠活动
大模型
产品
解决方案
定价
更多

IDE 2021-03中Selenium可执行Jar失效,DesiredCapabilities类导入报错

报错信息:The type org.openqa.selenium.remote.DesiredCapabilities is not accessible

问题原因
  • Jar包被添加到了模块路径(Modulepath) 而非类路径(Classpath),Java 9及以上版本的JPMS模块系统会限制未明确声明导出的包访问权限,导致无法访问org.openqa.selenium.remote下的类
  • Appium Java Client 7.5.1依赖的Selenium版本默认适配类路径导入逻辑,放置到模块路径下会触发访问权限校验错误
解决方法

方案一:调整Jar包导入路径(推荐)

  1. 移除当前添加到模块路径下的所有Selenium、Appium Java Client相关Jar包
  2. 重新将上述所有Jar包添加到项目的*类路径(Classpath)*下,不同IDE操作参考:
    • Eclipse:右键项目 → Build Path → Configure Build Path → Libraries标签 → 移除现有相关Jar → 点击Add JARs/Add External JARs导入Jar包,确认归类在Classpath分类下 → 点击Apply and Close
    • IDEA:File → Project Structure → Modules → Dependencies标签 → 移除现有相关Jar → 点击+号选择JARs or Directories导入Jar包 → 将导入Jar包的Scope设置为Compile,确认归属为Classpath → 点击Apply
  3. 清理项目缓存后重新编译,报错即可消失

方案二:保留模块路径的适配方法

如果必须使用模块路径,在项目的module-info.java模块描述文件中添加如下声明即可:

module 你的模块名 {
    requires org.seleniumhq.selenium.remote_driver;
    // 如有其他模块依赖可同步补充
}
验证

修复完成后可正常实例化DesiredCapabilities类,无导入报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 04:24:04