How to click on an item inside a RecyclerView in Espresso

前端 未结 10 2325
逝去的感伤
逝去的感伤 2020-12-01 05:33

I have a RecyclerView (R.id.recyclerView) where each row has an image (R.id.row_image) and a TextView. I want to click on the image in the first row.
I\'ve tried to use

10条回答
  •  猫巷女王i
    2020-12-01 05:41

    Use RecyclerViewActions

    onView(withId(R.id.recyclerView))
        .perform(actionOnItemAtPosition(0, click()));
    

    Include this in your gradle script:

    dependencies {
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
        androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
    }
    

提交回复
热议问题