Unable to scroll Android app with Appium using Java Client

mc-sm9 :

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 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:

  1. Approach: scrollIntoView() (various implementations)
  2. driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
    • Source: Udemy course
    • Error: Does not scroll and NO error

  3. Approach: Try catch > scrollIntoView()
  4. try { driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))"); }catch(Exception e) { System.out.println("We got an error scrolling!"); }
    • Source: https://stackoverflow.com/questions/39658626/how-to-scroll-top-to-botton-using-android-driver
    • Error: Partially works: the page scrolls down but not far enough

  5. Approach: Swipe
  6. driver.swipe(0, Startpoint,0,scrollEnd,1000);
    • Source: https://stackoverflow.com/questions/39130591/swipe-or-scroll-to-bottom-in-appium-android
    • Error: Swipe is deprecated

  7. Approach: touchAction.longPress + moveTo
  8. ...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
    • Source: https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
    • Error: "driver cannot be resolved"

  9. Approach: touchAction.longPress + moveTo
  10. TouchAction touchAction = new TouchAction(driver); touchAction.longPress(10, 10).moveTo(x, y).release().perform();
    • Source: https://stackoverflow.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)"

  11. Approach: touch.longPress + moveTo
  12. ...TouchAction touch = new TouchAction(driver); touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
    • Source: https://stackoverflow.com/questions/50304699/how-to-scroll-to-specific-element-inlatest-version-of-appium-using-java
    • Error: "takeaway cannot be resolved"

  13. Approach: moveTo + using coordinates
  14. 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!

  15. Approach: Using Press Approach to swipe + moveTo
  16. TouchAction().press(el0).moveTo(el1).release();
    • Source: https://stackoverflow.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"

  17. Approach: touchAction 'tap' using coordinates
  18. 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!

  19. Approach: UiScrollable > Specify Parent scrollable frame and Child element
  20. 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"

  21. Approach: UiScrollable > Specify Parent scrollable frame and 'scrollIntoView' child element
  22. 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

  23. Approach: Changed “scrollable” attribute for page elements from “false” to “true” using CSS styles
    • 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.

  24. Approach: Touch actions: “mobile: swipe”, “mobile: scroll” (http://appium.io/docs/en/writing-running-appium/touch-actions/)
  25. JavascriptExecutor js = (JavascriptExecutor) driver; HashMap params = new HashMap(); params.put("direction", "up"); js.executeScript("mobile: swipe", params);
    • Source: https://stackoverflow.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."

  26. Approach: HashMap + scrollObject.put
  27. 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."

  28. Approach: Adjusted context of app from "native" to "webview" (since it's a Cordova app)
  29. 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)"
toasty :

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:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=68539&siteId=1