My situation
I want to write UI-tests for an Android App and therefore I need to scroll in some of the App's fragments. The tests are written in Kotlin, Appium version is v1.15.1 .
My problem
I use the standard approach for scrolling(see below) and it works fine, as long as the coordinates of my starting point don't fall onto a clickable element. I also observed this behaviour when navigating through the App with the Appium Desktop Inspector.
My current approach
PlatformTouchAction(driver as AppiumDriver)
.press(PointOption.point(100, 500))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo(PointOption.point(100, 100))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.release()
.perform()
As mentioned before this works if the starting point (100,500) is not on a clickable element.
If for example a button happens to be at (100,500) the scroll/swipe is not performed, but in fact on scroll listeners are still called.
You can scroll with help of resource id of element. This can be achieved with
UiAutomator2asautomation engine.You need to use automation name asUiAutomator2in desires capabilities.Add in desired capability
UiAutomator2if you are using appium as automation engine.Now use below functions if you have element's resource id, and index as 0 if there is one element on page.
This is dynamic approach it will scroll till element is not visible.