简体   繁体   中英

Error: Unable to initialize main class base Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/Capabilities

I have looked through all the solutions, but all of them are vague. They just tell to add jar files, but don't specify which ones and from where. The links provided are also very vague. Besides this, another solution was to add jar files to classpath, not module path, but I am unable to find where either of them are located in the configure path option. Following 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 void main(String[] args) throws MalformedURLException { 
        // TODO Auto-generated method stub
        File f=new File("src");
        File fs=new File(f, "app-debug.apk");
    
        DesiredCapabilities cap=new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus_5X_API_30_2");
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
        cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
        AndroidDriver<AndroidElement> driver=new AndroidDriver<>(new 
        URL("http://127.0.0.1:4723/wd/hub"),cap);

    }

}

Make sure you download the jar official website :

https://www.selenium.dev/downloads/ And add it by going to : File>Project structure>Modules>Dependencies and clicking the “+” checkbox to add a new jar file and select the one you downloaded (make sure it is latest version)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM