Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UiAutomator 2.0 Equivalent of scrollIntoView

I'm starting to use UiAutomator in a project I'm working on and wanted to start using the latest and greatest UiAutomator 2.0. I know that in earlier versions of UiAutomator you could scroll through a list searching for an item like so:

device.findObject(new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Search Text")));

Although this is possible in the newest version of the library, it is deprecated. I'd like to use the non-deprecated parts of the library to accomplish this. I've searched for examples far and wide and have been unable to find anything.

To summarize what I want, I want to do something similar to scrollIntoView (documentation here) using the result of device.findObject(By.scrollable(true)).

like image 739
Mike Holler Avatar asked Sep 06 '25 03:09

Mike Holler


1 Answers

UiObject2 has a scrollUntil() method which you can give a Condition<T,U> to and will return the matching object if found.

val searchText = device.findObject(By.scrollable(true))
  .scrollUntil(Direction.Down, Until.findObject(By.text("Search Text")
like image 74
Nicholas Avatar answered Sep 08 '25 01:09

Nicholas