1

I am doing automation testing on my Android app and am required to scroll in order to get visible the fields which are required to get scrolled.
I tried using the below code from here:

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

After running this code it is giving me this error:

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

Well, I know I've passed the driver in TouchActions which is of type AndroidDriver.

How would I fix this?

tambre
  • 4,625
  • 4
  • 42
  • 55
nimesh
  • 83
  • 1
  • 8
  • What do you want actually? Scrolling or Scroll to any specific element? – Al Imran Jun 22 '18 at 11:20
  • for now, I need scrolling. thanks – nimesh Jun 22 '18 at 11:31
  • Possible duplicate of [Android - Appium Swipe down not working](https://stackoverflow.com/questions/50636520/android-appium-swipe-down-not-working) – Al Imran Jun 22 '18 at 11:34
  • Here is the answer: https://stackoverflow.com/questions/50636520/android-appium-swipe-down-not-working/50636622#50636622 – Al Imran Jun 22 '18 at 11:34
  • well, it is giving me an error on the last line of the function where you have defined the TouchAction(); "new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();" that is "The constructor TouchAction(AppiumDriver) is undefined" can you please help me with this error. – nimesh Jun 23 '18 at 04:13
  • You have to import `import io.appium.java_client.TouchAction;` – Al Imran Jun 24 '18 at 14:17

1 Answers1

0

Please use TouchAction instead of TouchActions

 TouchAction action = new TouchAction(androidDriver);
    int height = androidDriver.manage().window().getSize().height;
    int width = androidDriver.manage().window().getSize().width;
    action.press(PointOption.point(width / 2, height / 2))
            .moveTo(PointOption.point(width / 2, height * 3 / 4)).release().perform();
J.Lyu
  • 932
  • 7
  • 16