实例化AndroidDriver时遇java.lang.NoClassDefFoundError: Rotatable错误求助
解决实例化AndroidDriver时出现java.lang.NoClassDefFoundError: org/openqa/selenium/Rotatable的问题
这个错误核心原因是Selenium 3.x及后续版本移除了Rotatable接口,而你的Appium Java Client依赖仍在调用该接口,大概率是依赖版本不兼容或冲突导致的。以下是针对性解决步骤:
1. 确保Appium与Selenium版本兼容
Appium Java Client和Selenium有严格的版本对应关系,比如:
- Appium Java Client 7.x 必须搭配 Selenium 3.x(推荐3.141.59)
- Appium Java Client 8.x+ 必须搭配 Selenium 4.x
在pom.xml中明确指定匹配的版本,示例:
<!-- Appium Java Client 7.6.0 搭配 Selenium 3.141.59 --> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.6.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency>
2. 排查并解决Maven依赖冲突
执行mvn dependency:tree命令查看项目依赖树,检查是否有多个版本的Selenium被间接引入。如果发现高版本Selenium,在对应的依赖中排除它,示例:
<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.6.0</version> <exclusions> <exclusion> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> </exclusion> </exclusions> </dependency>
3. 清理本地Maven仓库
本地仓库的依赖包可能损坏,手动删除.m2/repository/org/openqa/selenium目录下的所有文件,然后执行mvn clean install重新拉取完整依赖。
4. 清除IDE缓存
如果使用IntelliJ IDEA或Eclipse,清理IDE的缓存:
- IntelliJ:
File -> Invalidate Caches...,勾选Clear file system cache and local history后重启IDE - Eclipse:
Project -> Clean,选择项目后执行清理
内容的提问来源于stack exchange,提问作者KaPatil
相关产品推荐
相关产品推荐

