question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.MobileDriver

See original GitHub issue

The problem

I am getting below error message on line where i used “TouchAction action = new TouchAction((MobileDriver)driver);”

Please what should i do to remove below error.

ERROR MESSAGE: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.MobileDriver at com.qa.DragAndDrop.DragandDrop.getDesireCapabilities(DragandDrop.java:54) 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:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Environment

  • Appium version : 1.6.5 this i am using from command line.
  • Last Appium version that did not exhibit the issue (if applicable): v1.1.0-beta.4 (this is UI version) {This is with UI}
  • Desktop OS/version used to run Appium: Window 7 proffesional / 64 bit
  • Node.js version (unless using Appium.app|exe): Node.js 6.11.0 (x64) and npm
  • Mobile platform/version under test: 4.2.1
  • Real device or emulator/simulator: Real Device
  • Appium CLI or Appium.app|exe: Appium CLI

Code To Reproduce Issue :

package com.qa.DragAndDrop; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver;

import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileDriver; import io.appium.java_client.TouchAction; import io.appium.java_client.remote.MobileCapabilityType;

public class DragandDrop { //WebDriver driver; //AppiumDriver<AppiumWebElement> driver; RemoteWebDriver driver;

String device = "Android"; 
String devicename = "0123456789ABCDEF";
String platformversion = "4.2.1";
String platformname = "Android";

@Test
public void getDesireCapabilities() throws MalformedURLException, InterruptedException
{
	
	
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability("device", device);
	/*cap.setCapability(MobileCapabilityType.DEVICE_NAME, devicename);
	cap.setCapability(MobileCapabilityType.PLATFORM_NAME, platformname);
	cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformversion);*/
	cap.setCapability("deviceName", devicename);
	cap.setCapability("platformName", platformname);
	cap.setCapability("platformVersion", platformversion);
	cap.setCapability("browserName", "");
	cap.setCapability("appPackage", "com.mobeta.android.demodslv");
	cap.setCapability("appActivity", "com.mobeta.android.demodslv.Launcher");
	cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");
	
	driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"),cap);
	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
	driver.findElement(By.xpath("//android.widget.TextView[@text='Basic usage playground']")).click();
	
	WebElement source = driver.findElement(By.xpath("//android.widget.TextView[@text='Chick Corea']"));
	WebElement destination = driver.findElement(By.xpath("//android.widget.TextView[@text='Wayne Shorter']"));
	
	TouchAction action = new TouchAction((MobileDriver)driver);
	System.out.println("Dragging item");
	action.longPress(source).moveTo(destination).release().perform();
	System.out.println("Dragged Succssfully");
	//driver.quit();
	
}

}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

18reactions
kapilrana16commented, Jul 7, 2017

closing this issue, i got the solution.

3reactions
mygithub07commented, Oct 30, 2017

You should post the solution for others

Read more comments on GitHub >

github_iconTop Results From Across the Web

RemoteWebElement can not be cast to io.appium.java_client ...
Hi I am getting below error - Exception in thread “main” java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be ...
Read more >
ClassCastException with new Appium-java TouchActions
Solution is to use Appium TouchAction instead of Selenium TouchActions . import io.appium.
Read more >
WindowsDriver (java-client API) - javadoc.io
Executes JSONWP command and returns a response. org.openqa.selenium.remote.Response, execute(java.lang.String driverCommand, java.util ...
Read more >
Unable to do Appium Touchaction in Serenity - Google Groups
java.lang.ClassCastException: net.thucydides.core.webdriver.WebDriverFacade cannot be cast to io.appium.java_client.MobileDriver,.
Read more >
WindowsElement (java-client 6.1.0 API) - GitHub Pages
Class WindowsElement. java.lang.Object. org.openqa.selenium.remote.RemoteWebElement. io.appium.java_client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found