title: Testing included views with Espresso
body: <p>I'm trying to reach a TextView and an ImageView within an included view with Espresso, but I always get the following error:</p>
  
  <pre><code>No views in hierarchy found matching: with id: ???:id/llMenuBtnSearch
  If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView{66d0aa9 V.ED.VC.. ........ 0,0-720,892 #7f090117 app:id/listView}
  </code></pre>
  
  <p>I don't know what "use Espresso.onData to load it" means.</p>
  
  <p>I tried to find an answer in the following sources:</p>
  
  <p><a href="https://stackoverflow.com/questions/27890101/espresso-select-children-of-included-layout">Espresso select children of included layout</a></p>
  
  <p><a href="https://developer.android.com/training/testing/espresso/recipes" rel="nofollow noreferrer">https://developer.android.com/training/testing/espresso/recipes</a></p>
  
  <p><a href="https://www.programcreek.com/java-api-examples/index.php?api=android.support.test.espresso.matcher.RootMatchers" rel="nofollow noreferrer">https://www.programcreek.com/java-api-examples/index.php?api=android.support.test.espresso.matcher.RootMatchers</a></p>
  
  <p>But, until now, I was unable to find a solution.</p>
  
  <p>My view hierarchy:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:focusableInTouchMode="true"
      tools:context="com.sentilant.driviantasks.navigation.Navigation.MapMaster"
      android:tag="mapMaster"&gt;
  
      ...
  
          &lt;android.support.design.widget.CoordinatorLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
              ...
  
              &lt;include
              android:id="@+id/vRouteDetails"
              layout="@layout/route_details"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_margin="20dp"
              android:visibility="invisible" /&gt;
  
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>And the included layout (included with id:vRouteDetails in the parent layout)</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="20dp"
      android:background="@drawable/layout_background"
      android:orientation="vertical"&gt;
  
      &lt;android.support.design.widget.CoordinatorLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="5dp"&gt;
  
          &lt;ImageButton
              android:id="@+id/ibRDetailsClose"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="5dp"
              android:background="@null"
              app:srcCompat="@drawable/menu_ic_back"
              tools:ignore="ContentDescription" /&gt;
  
          &lt;TextView
              android:id="@+id/tvRDetailsTitle"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:gravity="center"
              android:text="@string/route_details_title"
              android:textSize="18sp"
              tools:text="Route Details" /&gt;
  
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I'm trying to reach both the ImageButton and the TextView.
  Like so:</p>
  
  <pre><code>onView(allOf(withId(R.id.ibRDetailsClose), withParent(withId(R.id.vRouteDetails))))
                  .perform(click());
  </code></pre>
  
  <p>Is there a solution I missed?</p>
  
  <p>Thank you in advance.</p>