Espresso, how to click on the ImageView placed in the first element of the list?

I have my own layout for listview, I want to click on the image placed in the list item, the overflow icon of the first item in the list view.

I want to click on the last image with id "rcOverflow"

My layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingTop="5dp">

<ImageView
    android:id="@+id/rcCircle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignWithParentIfMissing="true"
    android:layout_alignParentTop="true" />

<TextView
    android:id="@+id/rcTime"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:gravity="right"
    android:maxLines="1"
    android:textColor="#ffffff"
    android:textSize="13sp" />

<RelativeLayout
    android:id="@+id/rsBubble"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:layout_alignWithParentIfMissing="true"
    android:layout_below="@id/recordsMonthHeader"
    android:paddingBottom="16dp"
    android:paddingTop="16dp">

    <ImageView
        android:id="@+id/rcImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:layout_alignParentTop="true"
        android:visibility="gone"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="4dp"/>

    <TextView
        android:id="@+id/rcFilename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:textColor="#000000"
        android:maxLines="2"
        android:ellipsize="end"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/rcDuration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/recordsFilename"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="2dp"
        android:textColor="#a09f9f" />

    <ImageView
        android:id="@+id/records_location_image"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:layout_alignBottom="@id/recordsDuration"
        android:layout_marginBottom="4dp" />

    <TextView
        android:id="@+id/rcLocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/recordsDuration"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="3dp"
        android:layout_marginTop="2dp"
        android:ellipsize="end"
        android:lines="1"
        android:textColor="#a09f9f"
        android:textSize="12sp"
        android:visibility="gone" />

    <TextView
        android:id="@+id/rcTag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/recordsDuration"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="3dp"
        android:textColor="#a09f9f"
        android:textSize="12sp"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/rcOverflow"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_below="@+id/recordsImage"
        android:layout_alignParentRight="true"
        android:layout_alignWithParentIfMissing="true"
        android:background="?android:attr/selectableItemBackground"
        android:src="@drawable/overflow" />

</RelativeLayout>

what i tried

onData(anything()).inAdapterView(withId(getId("recorderlistpage_listView")))
.perform(click());

or

onData(anything()).atPosition(0).inAdapterView(withId(getId("rcOverflow")))
.perform(click());

both do not work

+4
source share
3 answers

It worked for me

onData(allOf()).atPosition(0).
onChildView(withId(R.id.rcOverflow)).
perform(click());
+1
source

I'm not too sure, but what about this?

onData(anything())
    .inAdapterView(withId(R.id. recorderlistpage_listView))
    .atPosition(0)
    .onChildView(withId(R.id.rcOverflow))
    .perform(click());
+4
source

@saamzzz see this ship

    // open the Drawer and select rubric at position 0
    final int first_position = 0;
    DrawerActions.openDrawer(R.id.drawer_layout);
    onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
    //// get position of last rubric
    final int last_position = ((ListView) mActivity.findViewById(R.id.navDrawer_rubrics))
            .getAdapter().getCount() - 1;
    //// do select rubric around the middle
    onData(anything())
            .inAdapterView(withId(R.id.navDrawer_rubrics))
            .atPosition(first_position + last_position/2)
            .perform(click());
    onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
0
source

All Articles