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

Java新手使用Appium自动化测试遭遇java.lang.NoClassDefFoundError问题求助

Fixing 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

  1. Add the matching selenium-remote-driver dependency
    Your current config is missing an explicit selenium-remote-driver dependency that matches your selenium-java version. 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.

  2. 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:tree
    

    If you find entries for org.seleniumhq.selenium:selenium-remote-driver with 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>
    
  3. 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 -U
    
  4. Verify 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 20:07:36