How to scroll a list from a script in APPIUM

Hi, I am working with APPIUM on Android. I need to scroll through the list page. I tried to do the 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 scrolls continuously until the last item is displayed. What I need to do is scroll through the list page.

+7
source share
3 answers

It 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();
   }
+2
source

With its scrollable list of how to use UiScrollablee.g.

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

Additional options here

0
source

@Abhay Jangde Iam " press (PointOption) TouchAction (WebElement)"

0
source

All Articles