Java新手使用Appium自动化测试遭遇java.lang.NoClassDefFoundError问题求助
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/CommandPayload in Appium + Selenium Test Hey there! Let's break down why you're hitting this error and walk through how to fix it.
What's causing this issue?
The CommandPayload class was introduced in Selenium 4.x, but you're using Selenium 3.141.59. Even though you checked compatibility between Appium 7.3.0 and Selenium 3.141.59, there's likely a dependency conflict happening behind the scenes—your Appium Java Client might be pulling in a newer Selenium version transitively, creating a mismatch when your code tries to access a class that doesn't exist in your explicitly declared Selenium 3.x setup.
Step-by-Step Fixes
Add the matching
selenium-remote-driverdependency
Your current config is missing an explicitselenium-remote-driverdependency that matches yourselenium-javaversion. Add this to your<dependencies>block:<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> <version>3.141.59</version> </dependency>This ensures all Selenium components run on the exact same version, eliminating version mismatches.
Check for hidden dependency conflicts
Run this Maven command to view your full dependency tree and spot any unexpected Selenium versions being pulled in:mvn dependency:treeIf you find entries for
org.seleniumhq.selenium:selenium-remote-driverwith a version higher than 3.141.59, exclude that conflicting transitive dependency from your Appium Client config:<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.3.0</version> <exclusions> <exclusion> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> </exclusion> </exclusions> </dependency>Clean and refresh your Maven dependencies
Cached outdated dependencies can cause weird issues. Run these commands to clear old artifacts and re-download fresh, consistent ones:mvn clean mvn install -UVerify version compatibility (optional fallback)
If the above fixes don't work, try upgrading your Appium Java Client to a slightly newer version (like 7.6.0) which has more robust compatibility with Selenium 3.141.59:<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.6.0</version> </dependency>
Quick note on your test code
Your test setup looks totally solid—once the dependency issues are resolved, that code should run without problems. Just double-check that your Appium server is running at http://127.0.0.1:4723/wd/hub and your emulator/device is ready to go.
内容的提问来源于stack exchange,提问作者Naruto

