Filipe Ramos Filipe Ramos - 1 month ago 26x
Android Question

Using Espresso to click view inside RecyclerView item

How can I use Espresso to click a specific view inside a RecyclerView item? I know I can click the item at position 0 using:

.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));

But I need to click on a specific view inside that item and not on the item itself.

Thanks in advance.

-- edit --

To be more precise: I have a RecyclerView (
) which items are CardView (
). Inside each CardView I have four buttons (amongst other things) and I want to click on a specific button (

I would like to use the new features of Espresso 2.0, but I'm not sure that is possible.

If not possible, I wanna use something like this (using Thomas Keller code):

onRecyclerItemView(, ???, withId(;

but I don't know what to put on the question marks.


You can do it with customize view action.

public class MyViewAction {

    public static ViewAction clickChildViewWithId(final int id) {
        return new ViewAction() {
            public Matcher<View> getConstraints() {
                return null;

            public String getDescription() {
                return "Click on a child view with specified id.";

            public void perform(UiController uiController, View view) {
                View v = view.findViewById(id);


Then you can click it with

            RecyclerViewActions.actionOnItemAtPosition(0, MyViewAction.clickChildViewWithId( bt_deliver)));