Collect all elements from a list with scroll

Hello

Im testing an android app and need to test a page which contains a list of accounts.
Each account has the same fields with different data.
I have an android element list which contain all those accounts, the only problem is that it saves only the accounts it can see.
meaning - - > we need to scroll each time to collect more accounts until there are no more.
My question is, is there a smart/elegant way to that? (I know that scrollTo is deprecated).
Is there a way to use UiScrollable?

Thank :slight_smile:

2 Likes

in most cases:

String text = "your_text";
driver.findElement(MobileBy
                    .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                            + "new UiSelector().text(\""+text+"\"));"))

sometimes you need to specify “new UiScrollable(new UiSelector())” like e.g. by id:

driver.findElement(MobileBy
                    .AndroidUIAutomator("new UiScrollable(new UiSelector().resourceIdMatches(".*id/your_scrolling_container_id")).scrollIntoView("
                            + "new UiSelector().text(\""+text+"\"));"))

@Aleksei, thanks for the quick comment.

I am trying to do so on the Contacts app on android:

This works fine: (and returns the list that you can see in the print screen)

driver.findElementsByAndroidUIAutomator(“new UiScrollable(new UiSelector().”
+“scrollable(true)).scrollIntoView(new UiSelector().resourceId(“android:id/list”))”);

my question is now, how can I concatenate more function to this line of code?

I want to scroll to a specific elements (lets say contact J ).

thanks again

then something like:

String text = "J";
driver. findElementsByAndroidUIAutomator("new UiScrollable(new UiSelector().resourceId(\"android:id/list\")).scrollIntoView("
                            + "new UiSelector().text(\""+text+"\"));"))

Hi @Aleksei

I tried the exact code you wrote but its not scrolling, nothing actually happens.
I tried with diffrent contacts (beside “J”) but still no scrolling…

Suppose a case where no text is available and the locators are same then how to get the element till scroll to bottom?

@ankit_gupta how human can understand that we have bottom?

Scroll bar hits bottom, and after a (typically 2-4 second for infinite scroll) delay, the scroll remains. If text is not available, take a screen shot and confirm in OpenCV that the screen is not changing after swipe/TouchAction.