I know there has been many responses, here is what I use,
public boolean scrollToElement (By by) throws Exception {
boolean isFoundTheElement = appiumServer.getDriver().findElements(by).size() > 0;
while (isFoundTheElement == false) {
swipeVertical(0.8, 0.1, 0.5, 2000);
isFoundTheElement = appiumServer.getDriver().findElements(by).size() > 0;
}
return isFoundTheElement;
}
public void swipeVertical (
double startPercentage, double finalPercentage, double anchorPercentage, int duration)
throws Exception {
Dimension size = appiumServer.getDriver().manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
getTouchAction().press(PointOption.point(anchor, startPoint))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))
.moveTo(PointOption.point(anchor, endPoint)).release().perform();
}
public TouchAction getTouchAction () {
return new TouchAction(appiumServer.getDriver());
}