How to determine I have reached the end of a scrollable using TouchAction?

I have implemented a looping scrolling method using TouchAction to search for a text on the screen. However, I do not know how to determine when I have reached the end of the page. The data we use is dynamic so it can either take 5 swipes or up to 20 to reach the bottom. I originally used UiScrollable but because the data fills up the page dynamically, when network speed is slow, the UiScrollable will fail because it thinks it has reached the end of the page even though data is still loading.

For now, I just have a while loop that swipes until it finds the specified text. I put an int counter as a temporary failsafe, but would like to know if there’s a way to determine that we’ve truly reached the end of the page and no new data will be loaded.

I’d say there is no reliable way to determine that being locked in a black box. You could ask devs to add some flag, for example into app logs or into the UI, which could be detected by UIA and confirm there is no more data to load.

1 Like

I see. I tried to implement a workaround, I’ll explain it here for anyone that might find it useful.

I use driver.findElements() to get all elements on the screen with a certain attribute, ex. get all search result items. I then retrieve the last element in the List and save it’s Location using getLocation(). After every swipe, I get the last displayed element again, and compare it’s Location to the one I saved. If the values match, that means the elements on the screen are no longer moving after a swipe. I added a counter as well to check if the Location values match 3 times; that means we’ve reached the bottom of the page (this is to ensure the script doesn’t stop when the page is just loading new data and hasn’t reached the true bottom yet).

Alternatively, you can get the element’s text value, or anything else. The basic approach is to compare the last element on the screen with the previous last element and determine if they’re the same.

This is basically what we’ve done. It should be an Appium pattern or something.

1 Like

You can call driver.getPageSource() and compare whether the contents has changed between swipes. If it has, then you’re not at the end of the page. If it stays the same, it means the swipe didn’t affect anything on the page i.e. you’re at the end of the page.