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


#1

Hi!
I wrie automated tests for Android native application and forced with scroll/swipe problem.

I need to scroll through Android application, and use next method for this : http://appium.io/docs/en/commands/interactions/touch/scroll/

TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();

But in first line I’m getting an exception " java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen"

My environment is: java, jdk 1.8.0_65, appium 1.6.1


#2

This is a guess but you might have a mismatch between your versions of appium, java-client, and selenium-java…
Try upgrading your appium version to 1.8 and then upgrade the corresponding libraries…
I have:
appium = 1.8
io.appium.java-client = 6.0.0
org.seleniumhq.selenium.selenium-java = 3.9.1
JDK = 1.8

I dont get that error from my use of

new TouchActions(driver);

Good Luck!


#3

Hi!

I still have this issue at this moment…

Appium version : 1.8.1
jdk version 1.8.092
org.seleniumhq.selenium.selenium-java : 3.141.59
io.appium java-client: 6.1.0

TouchActions action = new TouchActions(driver);
action.scroll(10, 300);
action.perform();

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


#4

Hi,

I am getting same error with TouchActions.I have tried with appium java client 6.0.0 as well,still facing the issue.Any help would be appericiated.

Appium Version:1.10.0
jdk Version: 1.8.0_191
java-Client-6.1.0

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


#5

Hi!

(This was somewhat of java 6 language specific thing)
After multiple tries and pages, here is what I found as a working solution:

public void scrollDown()  {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //x position set to mid-screen horizontally
    int width = size.width / 2;

    //Starting y location set to 80% of the height (near bottom)
    int startPoint = (int) (size.getHeight() * 0.80);

    //Ending y location set to 20% of the height (near top)
    int endPoint = (int) (size.getHeight() * 0.20);

    new TouchAction(driver).press(PointOption.point(width, startPoint)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000))).moveTo(PointOption.point(width, endPoint)).release().perform();

}

My driver is a public property on top of the class:

public AppiumDriver<MobileElement> driver;

Instantiated in @BeforeMethod

driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”),caps);