Clicking inside a Recycler view: Espresso
<p>I am trying to click on a menu item inside Recycler view and I have following code.</p>

<pre><code>onView(allOf(withId(R.id.section_list),isDisplayed())).perform(RecyclerViewActions.actionOnItem(hasDescendant(withText("ABC")), MyViewAction.clickChildViewWithId(R.id.payment_menu)));
</code></pre>

<p>and MyViewAction looks like this:</p>

<pre><code>class MyViewAction {

public static ViewAction clickChildViewWithId(final int id) {
    return new ViewAction() {
        @Override
        public Matcher&lt;View&gt; getConstraints() {
            return null;
        }

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

        @Override
        public void perform(UiController uiController, View view) {
            View v = view.findViewById(id);
            v.performClick();
        }
    };
}
</code></pre>

<ul>
<li>When I test it, I can see the Scrolling takes place to right position but the click fails with the following error</li>
</ul>

<blockquote>
  <p>android.support.test.espresso.PerformException: Error performing 'android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction@2fd64b56' on view 'with id: com.em3Agri.operation.debug:id/section_list'.
      at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
      at .........
      Caused by: java.lang.IllegalStateException: No view holder at position: 38
      at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:290)
      at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)</p>
</blockquote>