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:
- Appium version: 1.6.2
- Appium client: Java (java-client-6.1.0.jar)
- Android versions: 5.1, 6.0.1, 7.1.1
- Java version: jre1.8.0_171
- Selenium version: selenium-java-3.13.0
- App type: Cordova (hybrid); the app is built with Cordova but when running
System.out.println(driver.getContext());
, the result isNATIVE_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:
- Approach: scrollIntoView() (various implementations)
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
- Source: Udemy course
- Error: Does not scroll and NO error
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))");
}catch(Exception e) {
System.out.println("We got an error scrolling!");
}
- Source: https://stackguides.com/questions/39658626/how-to-scroll-top-to-botton-using-android-driver
- Error: Partially works: the page scrolls down but not far enough
driver.swipe(0, Startpoint,0,scrollEnd,1000);
- Source: https://stackguides.com/questions/39130591/swipe-or-scroll-to-bottom-in-appium-android
- Error: Swipe is deprecated
...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
- Source: https://stackguides.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- Error: "driver cannot be resolved"
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(10, 10).moveTo(x, y).release().perform();
- Source: https://stackguides.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- Error: "The method longPress(LongPressOptions) in the type TouchAction is not applicable for the arguments (int, int)"
...TouchAction touch = new TouchAction(driver);
touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
- Source: https://stackguides.com/questions/50304699/how-to-scroll-to-specific-element-inlatest-version-of-appium-using-java
- Error: "takeaway cannot be resolved"
actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
- Source: http://www.automationtestinghub.com/appium-scroll-examples/
- Error: The 'press' action is deprecated!
TouchAction().press(el0).moveTo(el1).release();
- Source: https://stackguides.com/questions/49004686/scroll-text-area-with-terms-and-conditions-on-hybrid-app-with-appium
- Error: "The method press(AndroidElement) is undefined for the type Object"
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(x, y)).perform();
- Source: https://discuss.appium.io/t/scrolling-to-element-in-android-app-using-java/17208
- Error: None; it partially works: the page scrolls down but not far enough!
MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText("
+ "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
- Source: https://stackoverflow.com/a/51003840/9214050
- Error: "Could not parse UiSelector argument: problem using reflection to call this method"
MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView("
+ "new UiSelector().resourceId(\"add-task-button\"))"));
sendEmailButton.click();
- Source: https://stackoverflow.com/a/51003840/9214050
- Error: Does not scroll and NO error
- Source: http://burnignorance.com/html-tips/making-a-smooth-scroll-view-for-android-ios-in-html/
- Error: none, but app won't scroll to bottom of page.
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap params = new HashMap();
params.put("direction", "up");
js.executeScript("mobile: swipe", params);
- Source: https://stackguides.com/questions/32387357/i-cant-make-swipe-gesture-work-for-me-in-appium-using-java#
- Error: "Unknown mobile command "scroll". Only shell,startLogsBroadcast,stopLogsBroadcast commands are supported."
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
- Source: http://appium.io/docs/en/writing-running-appium/touch-actions/
- Error: "Unknown mobile command "scroll". Only shell,startLogsBroadcast,stopLogsBroadcast commands are supported."
appCapabilities.setCapability("autoWebview", "true");
- Source: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
- Error: "Exception in thread "main" org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible."
- Error: "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '58.0.3029'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. (WARNING: The server did not provide any stacktrace information)"
new TouchActions(driver)
line: "Exception in thread "main" java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen". Do you have any suggestions? Thanks! – mc-sm9