Let's suppose you want to tap on buttonClick, which is the id of a button inside your RecyclerView.
I use this code:
onView(allOf(withId(R.id.buttonToClick), isCompletelyDisplayed()))
.perform(click());
This gets the view with this id which is currently displayed and performs a click on it.
Hope this helps.
P.S.: Also, on espresso-contrib there are RecyclerViewActions
that maybe you can use: actionOnHolderItem
, actionOnItem
and actionOnItemAtPosition
. You can do something like:
onView(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…