I am unable to scroll down to the bottom of any page in an Android app using Appium. Multiple approaches were attempted, including those found on Stack Overflow. (It seems this challenge is common.) However, all attempts failed.
Environment:
System.out.println(driver.getContext());
, the result is NATIVE_APP
Please share any alternatives or refinements that can solve this problem. Any helpful suggestions are greatly appreciated!
The following summarizes the various approaches that were attempted:
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))");
}catch(Exception e) {
System.out.println("We got an error scrolling!");
}
driver.swipe(0, Startpoint,0,scrollEnd,1000);
...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(10, 10).moveTo(x, y).release().perform();
...TouchAction touch = new TouchAction(driver);
touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
TouchAction().press(el0).moveTo(el1).release();
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(x, y)).perform();
MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText("
+ "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView("
+ "new UiSelector().resourceId(\"add-task-button\"))"));
sendEmailButton.click();
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap params = new HashMap();
params.put("direction", "up");
js.executeScript("mobile: swipe", params);
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
appCapabilities.setCapability("autoWebview", "true");
As a variation on the options proposed above, here is another way of implementing TouchAction
in combination with press
and moveTo
methods that worked for me. This results in a downward screen swipe. You might need to simply adjust the coordinates to whatever works best on your client:
new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();
For additional info, you might check out these references: