0

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec

Is this error because of dependencies? I inspected similar problems at Stack Overflow, but didn't came up with an idea how to fix it.

Here is my code:

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class base {
    
    public static AndroidDriver<AndroidElement> Capabilities() throws MalformedURLException {
        
        File appdir=new File("src");
        File app=new File(appdir,"ApiDemos-debug.apk");
        
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Emulator1");
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
        cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
        AndroidDriver<AndroidElement> driver=new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
        return driver;
    }

This is what I see after running the test:

    авг 13, 2019 11:26:55 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:86)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:96)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:94)
    at base.Capabilities(base.java:22)
    at basics.main(basics.java:12)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 14 more
5
  • There is similar answer already stackoverflow.com/questions/56933457/… Commented Aug 13, 2019 at 21:58
  • Possible duplicate of java.lang.NoClassDefFoundError: org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec Commented Aug 14, 2019 at 0:17
  • I saw this solution in some answers and that it can be set in maven but I dont know how <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.0.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.12.0</version> </dependency> Commented Aug 14, 2019 at 7:45
  • @Mykhailo Moskura - you are right, but unfortunately I have no idea about how to use maven or play with dependencies ( Commented Aug 14, 2019 at 8:52
  • You need to add dependency inside dependencies tag in pom.xml which is in root path of your project Commented Aug 14, 2019 at 9:41

1 Answer 1

1

You're suffering from a form of a Jar Hell due to:

  1. Appium Java Client 7.0.0 has Selenium Java 3.141.59 as a part of its transitive dependencies
  2. You explicitly declare Selenium Java Client 3.12.0 as your project dependency
  3. Java Classloading picks up the wrong classes with not matching APIs and dependencies - that's why you're getting this error

The solution is to remove Selenium Java Client 3.12.0 from your project dependencies/classpath, Maven will resolve the required dependencies on its own.

See Appium - Code Examples - Java article for more information and sample projects.

Sign up to request clarification or add additional context in comments.

2 Comments

It worked after adding commons-lang3-3.7 jar and changing java-client 7.1.0 jar to 7.0.0 in external libraries. Thanks anyway!
@VadimAbramenko Hello. I have the same issue as you but still can't figure the solution. Could you please help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.