How to use UiSelector to find an element based on siblings?

I’m trying to get a scrollable/recyclerview but it has no unique ID, and I must get the value of it’s sibling to find it. Here’s how it looks:

    `TextView ("Group Name")`

I can find the scrollable just fine by hardcoding an index like this:
String uiScrollable = "new UiScrollable(new UiSelector().resourceId(\"recyclerID\").instance(1)).setAsHorizontalList().scrollTextIntoView(\"Item\")";
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(uiScrollable));

But I need it to not use an index and find it based on the “Group Name”. I tried fromParent and childSelector but keep getting NoSuchElementException.

String uiScrollable = "new UiScrollable(new UiSelector().resourceId(\"recyclerID\").fromParent(new UiSelector().childSelector(new UiSelector().text(\"Group Name\")))).setAsHorizontalList().scrollTextIntoView(\"Item\")";
String uiScrollable = "new UiScrollable(new UiSelector().text(\"Group Name\").fromParent(new UiSelector().className(\"android.widget.LinearLayout\")).childSelector(new UiSelector().resourceId(\"recyclerID\")))

1 Like