Java – How to scroll using appium coordinates

How to scroll using appium coordinates… here is a solution to the problem.

How to scroll using appium coordinates

I’m trying to scroll in a native android app using the method below

Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
int endy = (int) (size.height * 0.20);
int startx = size.width / 2;

driver.swipe(startx, starty, startx, endy, 3000);
Thread.sleep(2000);

But in driver.swipe it gives me an error

The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver

Can anyone help me with this? I’ve been looking for a solution but have never been successful.

Solution

You can use TouchAction instead of .swipe:

TouchAction action = new TouchAction(driver);
action.press(x, y).moveTo(x, y).release().perform();

You can also implement x y using PointOption as follows:

  1. .press(new PointOption().withCoordinates(x, y))

    Or

  2. .press(PointOption.point(x, y))

After import:

import io.appium.java_client. TouchAction;

TouchAction

PointOption

Related Problems and Solutions