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))
.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With