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

解决Rotatable类NoClassDefFoundError错误及适配Selenium版本咨询

问题分析与解决方案

核心问题原因

  1. 依赖版本冲突:你的pom.xml中同时引入了selenium-java:4.19.1和selenium-remote-driver:4.0.0-alpha-6,版本严重不匹配。selenium-java本身已经包含了selenium-remote-driver模块,单独指定旧版本会导致类加载混乱,触发NoClassDefFoundError。
  2. Rotatable类的废弃:org.openqa.selenium.Rotatable类仅存在于Selenium 3.x版本中,从Selenium 4.x开始该类被移除,相关屏幕旋转功能被整合到其他API中。

具体解决步骤

1. 修复依赖配置

删除单独的selenium-remote-driver依赖,确保Selenium相关依赖版本统一。修改后的pom.xml依赖如下:

<dependency> 
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>4.19.1</version>
</dependency>
<!-- 添加兼容的Appium Java客户端依赖 -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>8.6.0</version> <!-- 与Selenium 4.19.1兼容的版本 -->
</dependency>

2. 替换Rotatable功能(如果需要屏幕旋转)

如果你的业务需要屏幕旋转操作,在Selenium 4+结合Appium的环境下,使用Appium提供的屏幕旋转API替代:

// 旋转为横屏
driver.rotate(ScreenOrientation.LANDSCAPE);
// 旋转为竖屏
driver.rotate(ScreenOrientation.PORTRAIT);

注意:需要确保导入正确的包io.appium.java_client.ScreenOrientation。

3. 修正代码中的AppActivity配置

你当前指定的appActivity是错误的,谷歌计算器的正确Activity应为com.google.android.calculator.Calculator,修改后代码如下:

cap.setCapability("appActivity", "com.google.android.calculator.Calculator");

补充说明

  • 确保Appium服务版本与Java客户端版本兼容,避免跨版本兼容性问题。
  • 所有依赖版本需保持一致或处于官方兼容范围内,避免随意混合不同主版本的依赖。

内容的提问来源于stack exchange,提问作者Vishal.B

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 03:03:15