How can I scroll an android app page from top to bottom using appium driver?

3.6k views Asked by At
  1. I want to scroll an android mobile app page from top to bottom.

  2. I have tried with below defined coding for scroll and click for specific web element using text. It works fine.

 // method 1
    driver.scrollTo("R");

    // method 2
    driver.ScrollToExact("Top");
  1. But I need to scroll an full article page from top to bottom, without using above scroll() methods. I have tried with below coding, but scroll action doesn't happens for me.

// scroll to bottom of an page

((JavascriptExecutor) driver) .executeScript("window.scrollTo(0,
document.body.scrollHeight)"); 
  1. How can I scroll an android app page from top to bottom using appium driver?
5

There are 5 answers

0
Sudhakar MK On

Use

driver.scrollTo("Text");

Note: Text content you can find from node detail screen of UI Automator Viewer Tool

0
medy75 On

You can use in loop:

page.swipe(SwipeElementDirection.UP, 400)
0
akhilesh gulati On
Step 1
public boolean isElementFound(String zoneName, String text, int index) {
        try{
            //text=text.concat("["+index+"]");
            //System.out.println(text);
            WebElement webElement = appiumDriver.findElement(By.xpath(text));
            System.out.println("isElementFound : true :"+text + "true");
            //ReportAppium.getSnapShot(appiumDriver);
        }catch(NoSuchElementException e){
            System.out.println("isElementFound : false :"+text);
            //ReportAppium.getSnapShot(appiumDriver, "isElementFound- "+text + "false");
            return false;
        }
        return true;
    }
Step 2

while(isElementFound(element)==false)
{
     public void swipe(int startx, int starty, int endx,int endy,int duration)
    {
        TouchAction touchAction = new TouchAction(appiumDriver);
        System.out.println(startx+" "+starty);
        System.out.println("Entering swipe");

            System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
            touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();

    }

}
0
Kiran Sk On

Use :

driver.scrollTo("text");

Where text is the name of the button(You can check the text in UIAutomatorviewer)

0
Masum On

Here you need to check everytime with a text in the loop, that appears on the bottom of the page. If the text found than break the loop.

Dimension screenSize = driver.manage().window().getSize();
int startx = screenSize.getWidth() / 2;
int endx = startx;
int starty = (int) (screenSize.getHeight() * 0.70);
int endy = (int) (screenSize.getHeight() * 0.20);
AndroidDriver androidDriver = (AndroidDriver) driver; // WebDriver to AndroidDriver
while(true) {
        // code to check with a text which is appears on the bottom of the page 
        //break;
        scroll(driver, startx, starty, endx, endy, 500);
        androidDriver.swipe(startX, startY, endX, endY, time);
}