Reputation: 107
I have a Horizontal RecyclerView
inside a vertical RecyclerView
. I'm using this code I found on other question:
onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(parentPosition)),
isDescendantOfA(withRecyclerView(R.id.childHorizontalRecyclerView).atPosition(childPosition)),
(withText("USA"))))
.perform(click());
// It is not working for parentPosition > 0
but this only works for first row of parent RecyclerView
.
How do I click on the element on the child RecyclerView of the second row of parent RecyclerView
?
Upvotes: 4
Views: 1162
Reputation: 107
I finally figured out the solution for this:
onView(allOf(
withId(R.id.childHorizontalRecyclerView),
withParent(
withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(2)
)
)
).perform(RecyclerViewActions.actionOnItemAtPosition(3, scrollTo()))
.check(matches(hasDescendant(withText("USA"))));
Upvotes: 6