How to scroll in appium using java code example

Example: How to scroll in appium using java

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();

}

Tags:

Java Example