Java-client: TouchActions throws java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen exception

Created on 23 Jan 2019  Â·  10Comments  Â·  Source: appium/java-client

Description

Trying to long press a mobile element by;

        TouchActions action = new TouchActions(driver);
        action.longPress(element);
        action.perform();

per example usage in;
http://appium.io/docs/en/commands/interactions/touch/long-press/

and getting ;

java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
    at org.openqa.selenium.interactions.touch.TouchActions.<init>(TouchActions.java:38)
    at stepdefinitions.Scenarios.i_longpress_contact(Scenarios.java:137)
    at ✽.I longpress contact contact(src\test\resources\features\Contacts.feature:76)

Environment

  • java client build version or git revision if you use some shapshot: 7.0.0
  • Appium server version or git revision if you use some shapshot: [email protected]
  • Desktop OS/version used to run Appium if necessary: Windows 10 Enterprise
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: npm: '6.5.0'
  • Mobile platform/version under test: Android 7.1.1
  • Real device or emulator/simulator: Real Device Motorola Moto E4 Plus

Other versions

    <aspectj.version>1.8.10</aspectj.version>
    <cucumber.version>4.2.2</cucumber.version>
    <cucumber.jvm.deps.version>1.0.6</cucumber.jvm.deps.version>
    <junit.version>4.12</junit.version>
    <selenium.server.version>3.141.59</selenium.server.version>
    <appium.java.client.version>7.0.0</appium.java.client.version>

Ecxeption stacktraces

https://gist.github.com/dokmetas/a196d76aa648b56543153e8a5659cb2c

Most helpful comment

@nurayttumer
below works for my configuration;

import org.openqa.selenium.interactions.Actions;

new Actions(driver).clickAndHold(element).perform();

All 10 comments

@dokmetas try to switch to io.appium.java_client.TouchAction<T> and io.appium.java_client.MultiTouchAction. It seems org.openqa.selenium.interactions.touch.TouchActions uses a lot of deprecated methods, I think there is a chance it will be deprecated and removed in future.

works with Actions API. Thanks.

@dokmetas How did you solve your problem ? can you explain it ? Where did you use the Actions Api

@saikrishna321 Same question , Where did you use the Actions Api ?

@nurayttumer
below works for my configuration;

import org.openqa.selenium.interactions.Actions;

new Actions(driver).clickAndHold(element).perform();

@nurayttumer Sorry for not explaining what is happening under the hood.

The W3C Actions API is very general, which also makes it abstract and a bit hard to understand. Basically, it has the concept of input sources, many of which can exist, and each of which must be of a certain type (like key or pointer), potentially a subtype (like mouse, pen, touch), and have a certain id (like "default mouse"). Pointer inputs can register actions like pointerMove, pointerUp, pointerDown, and pause. By defining one (or more) pointer inputs, each with a set of actions and corresponding parameters, we can define pretty much any gesture you like.

Default selenium new Actions(driver) does not work well for many cases in Appium as WDA and UIA2/Espresso looks for specific values, so we end up using Point API

WDA: https://github.com/appium/WebDriverAgent/blob/5896cce5a3ae386cf1874f3554ca462861a904df/WebDriverAgentTests/IntegrationTests/FBW3CTouchActionsIntegrationTests.m#L292-L300

Refer: https://appiumpro.com/editions/29

This issue still persist for me can you please elaborate the workaround for that?
This the error i am facing.

java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

at org.openqa.selenium.interactions.touch.TouchActions.<init>(TouchActions.java:38)
at MainImplementation.OtherFunctionFunctionalities.Request_MadicalClaim(OtherFunctionFunctionalities.java:30)
at TestCases.MainTestFile.Test3(MainTestFile.java:25)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

is there documentation for the Actions api?

@dokmetas Thank you so much, it worked!!!

Was this page helpful?
0 / 5 - 0 ratings