UIAutomator scrolling algorithm?


We’re using appium to automate an android app, using only UIAutomator strings, such as the following:

new UiScrollable(new UiSelector().resourceId("xyz").scrollable(true)).scrollIntoView(new UiSelector().resourceId("abc"))

Now there’s a problem where Appium/UIAutomator stops scrolling into one direction and starts scrolling into the opposite direction - even though the end of the scrollview has not been reached yet. To find hints towards why this is happening we need to know the algorithm that’s used by the scrolling function of appium/uiautomator.

How does the scrolling algorithm decide whether or not to change the scrolling direction?

  1. before starting to scroll opposite did few attempts where made to scroll in correct direction?
  2. where this few attempts really scroll happen?

my guess that it just tries to scroll and if scroll not happen -> then algorithm realize that scroll ends.

BTW in my observe first it tries to reach start scroll for sure then goes to end. Example: we have country list - Angola, England, USA. With default England selected. Then first it scroll into begining to Angola and then starting to look for needed value.

1 Like

Yes it starts scrolling into the correct direction but before reaching the end of the scrollview, it will scroll into the opposing direction. It will actually scroll up and down in the same bounds after that for a few times.

The question is, how does appium/UIAutomator recognize if a scrollview end has been reached or not. My current guess is, it will take elements inside the scrollview and compare the location of those elements before and after scrolling. If the location is the same after scrolling, it changes scroll directions.

We are using many very generic elements inside the app, for this reason I think the UIAuotmator might confuse another element for the one it scanned before scrolling and misjudges the descision to start scrolling into the opposite direction.

i.e. My guess is, the scroll algorithm has no certain way to tell if a scrollview end has been reached, instead it will guess based on child elements if the end has been reached or not

Appium does nothing here. This is pure UIAutomator command.

I never face any issue with scrolling or swiping if u r using uiscrollable class there is lot of methods to handle

refer this documentary

Hi @oscheller87

I am noticing exactly the same problem with the UIAutomator scrolling. I was thinking UIautomator gets confused due to the way my test app is constructed, but I guess I am not the only one with this issue. :slight_smile:

My automation also goes up and down a few times in the beginning and it scrolls to the correct direction.

This is unrelated to Appium, but I would also like to to know what’s going on.

1 Like

Hi, I faced with this problem too, is this bug of uiautomator?
It’s too long to wait while listview scroll down to the serached element.

1 Like

Is UiScrollable class applicable to everywhere in Appium or UiScrollable need to be true in UiAutomatorViewer

How to scroll if there is no text and resourceId present in element like in gallery section there is no text and content-desc and resourceId only classes are present for image

In your case you can hard code Swipe coordinates, base on your Screen size.