4

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?

Abhishek Sinha
  • 435
  • 4
  • 12
Amisha
  • 107
  • 7

1 Answers1

6

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")))); 
rakshakhegde
  • 924
  • 9
  • 15
Amisha
  • 107
  • 7