Can't get touch actions to work : AndroidDriver cannot be cast to....selenium.interactions.HasTouchScreen


#1

Hi, I am trying to get my AndroidDriver to scroll.

I am trying this:

WebElement secret = driver.findElement(By.id(“com.xxx.verifyxxxtestapp:id/oauth2_resource_edittext”));
TouchActions action = new TouchActions(driver);
action.scroll(secret, 10, 100);
action.perform();

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

I have imported: import org.openqa.selenium.interactions.touch.TouchActions; as that was the only class available to import. Should I be using an Appium on einstead?


#2

use Appium TouchAction instead of Selenium TouchActions


#3

Thanks mashKrum. I’ve got it to work using the following code to scroll by moving from one element location to another…thanks again :slight_smile:

    WebElement resource = driver.findElement(By.id("com.xxx.verify.xxxtestapp:id/oauth2_resource_edittext"));
    WebElement openid = driver.findElement(By.id("com.xxx.verify.xxxtestapp:id/oauth2_scope_edittext"));
    TouchAction action = new TouchAction(driver);
    action.press(resource).moveTo(openid).release();
    action.perform();