How to scroll an android pages using Appium driver and java?

  1. I want to scroll an android mobile web page from top to bottom.
  2. I have tried with below defined coding, it works fine.

// method 1
driver.scrollTo(“R”);

// method 2
driver.ScrollToExact(“Top”);

  1. I need to swipe an full article page from top to bottom. I have tried with below coding, but scroll action doesn’t happens for me.

// scroll to bottom of an page
@Test(priority=1)
public void scrollingToBottomofAPage() {
driver.navigate().to(URL);
((JavascriptExecutor) driver)
.executeScript(“window.scrollTo(0, document.body.scrollHeight)”);
}

@Selvi_Ranganathan: Were you able to scroll successfully from top to bottom? Could you provide me with the code you used?

@jigtest Hi,

  1. I have tried with below coding in mobile web page using web driver. Its work fine in scrolling from top to bottom in the mobile web page. Same code I have tried it in scrolling an android and iOS app page using appium driver. It doesn’t work at all.

// scroll up
((JavascriptExecutor) driver)
.executeScript(“window.scrollTo(0, document.body.scrollTop)”);

        // full scroll to bottom in slow motion
        for (int second = 0;; second++) {
            if (second >= 4) {
                break;
            }
            ((JavascriptExecutor) driver).executeScript(
                    "window.scrollBy(0,400)", "");
            sleep(2000);
        }
  1. For scrolling an android app till particular text, I have used below defined methods. Its works fine to scroll till an particular text. But, I want to scroll to top to bottom of an app page without using particular text.

    // method 1
    driver.ScrollToExact(“Text”);

    // method 2
    driver.scrollTo(“R”);

  2. How can I able to scroll an app page from top to bottom using java?

how can we scroll and we are using Web driver?

Hi Selvi,
can u plz share code to scroll down without knowing the last element.

Regards,
Zeeshan