7

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.

Abhay Jangde
  • 91
  • 1
  • 7

2 Answers2

2

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();
   }
Abhay Jangde
  • 91
  • 1
  • 7
0

Since its a scrollable list how about using UiScrollable, e.g.

driver.FindElement(MobileBy.AndroidUIAutomator("new UiScrollable(
    new UiSelector().scrollable(true).instance(0)).scrollIntoView(
    new UiSelector().resourceId(\"" + id + "\").instance(0))"))

More options here

dmle
  • 3,498
  • 1
  • 14
  • 22
  • Hi dmle, thanks for the reply , this also scroll the list to last element. what i want is to click first element of the list do something press back and click on next item and so on till the last element. Please provide any suggestion. – Abhay Jangde Dec 14 '17 at 06:54
  • without seeing your screen xml its hard to help you, but if you have elements with same attribute and use approach I posted in a right way => it should scroll to the first element, since it has `.instance(0)` – dmle Dec 14 '17 at 12:42