Reputation: 91
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.
Upvotes: 7
Views: 3579
Reputation: 91
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();
}
Upvotes: 2
Reputation: 3658
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
Upvotes: 0