The following code scrolls a list view very slowly so that I can get new elements that show when the scroll is over.
/**
* Scroll from the position of a given element to the border of the screen
/
fun iosScrollScreenFromOnePointToBorder(
driver: MobileDriver<>,
originPoint: Point,
swipeDirection: SwipeDirection
) {
val borderEdge = 10
val screenSize = driver.manage().window().size// should not click outside the screen border. For some reason on iOS, clicks near the border won't work, so // the origin point is reworked to half the size of the screen if (originPoint.x >= screenSize.width / 2) originPoint.x = screenSize.width / 2 if (originPoint.y >= screenSize.height / 2) originPoint.y = screenSize.height / 2 val destinationPoint = when (swipeDirection) { SwipeDirection.DOWN -> Point(originPoint.x, screenSize.height - borderEdge) SwipeDirection.UP -> Point(originPoint.x, borderEdge) SwipeDirection.LEFT -> Point(borderEdge, originPoint.y) SwipeDirection.RIGHT -> Point(screenSize.width - borderEdge, originPoint.y) else -> throw IllegalArgumentException("Diretion '$swipeDirection' not supported") } IOSTouchAction(driver) .press(PointOption.point(originPoint.x, originPoint.y)) .waitAction(WaitOptions.waitOptions(Duration.ofMillis(200))) .moveTo(PointOption.point(destinationPoint)).perform() }
The above operation indeed scrolls correctly, but is very slow. I wonder if there is a way to count or retrieve / cache elements or “elements DOM” while a scroll or swipes takes place, I mean, store elements while they are moving because of the scroll / swipe. Something like this:
// gets all the elements ‘passing’ while scrolling. The elements need to match the given xpath
elementsListWhileScrolling = getElementsWhileScrollingToTheEnd(By.xpath(“//XCUIElementTypeOther”))