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

5

2
  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?
Mellon answered 16/6, 2015 at 12:35 Comment(0)
N
1

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);
}
Normie answered 29/8, 2016 at 10:55 Comment(0)
A
0

You can use in loop:

page.swipe(SwipeElementDirection.UP, 400)
Alvira answered 11/8, 2015 at 11:30 Comment(0)
T
0

Use :

driver.scrollTo("text");

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

Threadfin answered 8/8, 2016 at 9:51 Comment(0)
S
0
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();

    }

}
Sanmiguel answered 14/2, 2017 at 10:8 Comment(0)
B
-1

Use

driver.scrollTo("Text");

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

Blanks answered 23/2, 2016 at 11:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.