Cannot instantiate the type AppiumDriver

return new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

Is there any changes in version 1.2.4.1 in using AppiumDriver?

If u r using JavaClient 2.0. so just instead of appiumDriver, just replace with AndroidDriver();

Thanks,
Priyank Shah

I’ve done that, but I have this error:

java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;

Can u provide more details. in the meantime u can refer this code.

also go through pom.xml to resolve dependencies.

Hello,

Did you manage to solve the problem? I am having the same issue, when trying to define an AndroidDriver i get

java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;

I realised my above post does not have sufficient details, I will try to provide that.
I am using java-client-2.0.0, selenium 2.43.1 and junit 4.11 libraries, and i have written the most basic driver definition i can think of, seen below:

@Test
public void test_123() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
AndroidDriver driver=new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
System.out.println(“success”);
}

And the error, as described above is

java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:40)
at test_class.test_123(test_class.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

As i am sort of a beginner when it comes to Appium i could really use some help or at least guidance in how to solve this.

Update:

If i run my project via Ant everything works fine. The error only occurs when trying to run the project from Eclipse. This is quite strange as i checked and all the settings seem fine, and nothing i did changed the outcome.
I will keep trying as I really want to be able to run from eclipse for the debug options, but if anyone knows a solution, that would be highly appreciated.

Same here, for now I just have my own AndroidDriver class that extends from AppiumDriver where scrollTo and scrollToExact are not implemented.

I use intellij when working on it…

Hello Every one ,

I am also having problem with:

My Code Is:


package test.java.io.appium.test.workshop;

import org.junit.Before;
import org.junit.Test;

public class AndroidMobileWebTest extends SauceTestClass {

@Before
public void setUp() throws Exception {
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("platformVersion", "4.3");
    capabilities.setCapability("browserName", "Browser");
    super.setUpAndroidDriver();
}

@Test
public void basicAndroidWebTest() throws Exception {
    runWebTest();
}

}


ERROR TRACED OUT AS:


java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:40)
at test.java.io.appium.test.workshop.AppiumTestClass.setUpAndroidDriver(AppiumTestClass.java:55)
at test.java.io.appium.test.workshop.AndroidMobileWebTest.setUp(AndroidMobileWebTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
at test.java.io.appium.test.workshop.AppiumTestClass.tearDown(AppiumTestClass.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Hi all,

I used to have the error until recently, and could not for the life of me fathom what was wrong. The problem arised because there was a mishmash of clients 1.7 and 2.1

In other words, inadvertadly I has both java-client 1.7 & java-client 2.1 in my classpath.

The error:

NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform 

Comes when you use IOSDriver (found in 2.1) and the appiumdriver is found in java-client 1.7…

I am facing same Error for Windows Can You please resolve it My Code IS:

package test.java.io.appium.test.workshop;

import org.junit.Before;
import org.junit.Test;

public class AndroidMobileWebTest extends SauceTestClass {

@Before
public void setUp() throws Exception {
    System.out.println("CP______________2");
    
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("browserName", "Browser");
    
    System.out.println("CP______________3");
    
    super.setUpAndroidDriver();
    
    System.out.println("CP______________4");
    
}

@Test
public void basicAndroidWebTest() throws Exception {
    runWebTest();
    System.out.println("CP______________1");
}

}

I’m getting the same error after updating to Java-Client-2.1.0

java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;

I’m getting error only when I run scripts through ANT…
Scripts runs fine when I run with TestNG…

public AndroidDriver initiateDriver() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“app-package”, package_Name);
caps.setCapability(“device”, “selendroid”);
caps.setCapability(“app-activity”, activity_Name);
caps.setCapability(“takesScreenshot”, true);
caps.setCapability(“device ID”, “uniquedeviceid”);
caps.setCapability(“app”, apK_Loc);
caps.setCapability(“platformName”, “Android”);
caps.setCapability(“deviceName”, “GT-I9300”);
caps.setCapability(“newCommandTimeout”, “500”);
caps.setCapability(“platformVersion”, “4.3”);
try
{
driver = new AndroidDriver(new URL(“http://localhost:4723/wd/hub”), caps);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}

Any solutions plz…

What are all jars you are using for this project and what classes you are importing…

Hi all,

As per the screenshot, can anyone please help me on fixing ‘desired capabilities’ as I am getting error.

If you are using the latest java client,write your code as :

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Test {

@SuppressWarnings("rawtypes")
public static AndroidDriver<MobileElement> driver;

public static void main(String[] args) throws MalformedURLException {
	// TODO Auto-generated method stub
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("deviceName", "Android");
	capabilities.setCapability("platformVersion", "5.1.1");
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("appPackage", "com.google.android.dialer");
	capabilities.setCapability("appActivity", "com.google.android.dialer.extensions.GoogleDialtactsActivity");
	
	 driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
	
	WebElement frameLayout = driver.findElement(By.id("com.google.android.googlequicksearchbox:id/layout"));
	//WebElement HorizontalScrollView =  frameLayout.findElement(By.className("android.widget.HorizontalScrollView"));
	List<WebElement> actionTab = frameLayout.findElements(By.className("android.view.View"));
	actionTab.get(2).click();
	//driver.findElement(By.linkText(linkText)

}

}

package test.com.mobiletest;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;

public class automation {

WebDriver driver;


public static final String USERNAME = "-";
public static final String ACCESS_KEY = "";
public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";

public static void main(String[] args) throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Nexus 5X API 24");
    capabilities.setCapability("platformVersion", "5.0");
    capabilities.setCapability("app", "");
    capabilities.setCapability("browserName", "");
    capabilities.setCapability("deviceOrientation", "portrait");
    capabilities.setCapability("appiumVersion", "1.6.5");

    WebDriver driver = new AndroidDriver<>(new URL(URL), capabilities);
    driver.findElements(By.xpath("//android.widget.TextView[@text='LOG IN']")).click();
    driver.quit();
}

}

and I have this error

automation.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
automation.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
^
automation.java:6: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
^
automation.java:7: error: package io.appium.java_client.android does not exist
import io.appium.java_client.android.AndroidDriver;
^
automation.java:11: error: cannot find symbol
WebDriver driver;
^
symbol: class WebDriver
location: class automation
automation.java:20: error: cannot find symbol
DesiredCapabilities capabilities = new DesiredCapabilities();
^
symbol: class DesiredCapabilities
location: class automation
automation.java:20: error: cannot find symbol
DesiredCapabilities capabilities = new DesiredCapabilities();
^
symbol: class DesiredCapabilities
location: class automation
automation.java:29: error: cannot find symbol
WebDriver driver = new AndroidDriver<>(new URL(URL), capabilities);
^
symbol: class WebDriver
location: class automation
automation.java:29: error: cannot find symbol
WebDriver driver = new AndroidDriver<>(new URL(URL), capabilities);
^
symbol: class AndroidDriver
location: class automation
automation.java:30: error: cannot find symbol
driver.findElements(By.xpath("//android.widget.TextView[@text=‘LOG IN’]")).click();
^
symbol: variable By
location: class automation
10 errors
please help