back to the question, got the solution for this case... thought to post it here for others! Having no answer to you question hurts sometimes... so here it is!
There are different ways depending on usage:
1. When you want to scroll to a particular index of an identifier. testData.getRoomTypeIndex() is just the index to which you . want to scroll, it could be 0, 1 etc...
UiScrollable roomSelection = new UiScrollable(new UiSelector().scrollable(true).className("android.widget.ScrollView"));
UiSelector selectRoom = new UiSelector().childSelector(new UiSelector().description("selectRoom").instance(testData.getRoomTypeIndex()));
try {
roomSelection.scrollIntoView(selectRoom);
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
2. When you just need to click on an element based on some text match, use this.
UiSelector pahFilter = new UiSelector().childSelector(new UiSelector().description("payMode_filter").childSelector(new UiSelector().textContains(payModeText)));
try {
mDevice.waitForIdle(3000);
UiObject filterPAH = mDevice.findObject(pahFilter);
filterPAH.click();
mDevice.waitForIdle(3000);
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
There are multiple ways to find an element based on UI hierarchy. We could do it based on the requirement and based on where the view/element exists on the screen. Ui automator library is a powerful tool for android automation.
This works perfectly on react-native screen, for android native the strings might need a tweak.
Hope this helps when it comes to scrolling on the view!