Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll the list from script in APPIUM

Hi I am working with APPIUM in Android. What I need to do is scroll the list page wise. I tried doing following.

    MobileElement element =(MobileElement)driver.findElement(By.className("android.widget.ListView"));
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> scrollObject = new HashMap<>();
    scrollObject.put("direction", "down");
    scrollObject.put("element", ((RemoteWebElement) element).getId());
    js.executeScript("mobile: scrollTo", scrollObject);

This works but the list get scrolled continuously till the last element is displayed. What I need to do is scroll the list page wise.

like image 289
Abhay Jangde Avatar asked Dec 13 '17 06:12

Abhay Jangde


1 Answers

This worked for me.

 List<WebElement> list = driver.findElements(By.xpath("//android.widget.TextView[@resource-id='com.imdb.mobile:id/label']"));

 if (list != null && !list.isEmpty()) {
   WebElement bottomElement = list.get(list.size() - 1);
   WebElement topElement = list.get(0);      
   TouchAction touchAction = newTouchAction(driver).press(bottomElement).moveTo(topElement).release();
   touchAction.perform();
   }
like image 123
Abhay Jangde Avatar answered Oct 06 '22 01:10

Abhay Jangde