Espresso can't click an ImageView
<p>my espresso instrumentation test can't click an ImageView:</p>
<blockquote>
<p>Error performing 'single click' on view 'with id: com.example.test:id/btnNext'.</p>
<p>Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.</p>
<p>Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission</p>
</blockquote>
<p>But what is strange that just three lines before it is able to click another ImageView looking quite similar to me. <strong>And using the app as human works as well</strong>.</p>
<p>Here is my minimal non-working example, do you see the error?</p>
<pre><code>@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestTest {

    @Rule
    public ActivityTestRule&lt;TestActivity&gt; _activityRule = new ActivityTestRule&lt;TestActivity&gt;(
            TestActivity.class);
    @Test
    public void testClicking() {
        onView(withId(R.id.btnPrevious)).perform(click());
        onView(withId(R.id.btnNext)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
        onView(withId(R.id.btnNext)).check(matches(isClickable()));
        onView(withId(R.id.btnNext)).perform(click()); // This line throws an exception
    }
}
</code></pre>
<p>The activity to test:</p>
<pre><code>public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity);
    }
}
</code></pre>
<p>And the layout file:</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    android:id=&quot;@+id/mainContainer&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:background=&quot;#FF000000&quot;&gt;

    &lt;LinearLayout
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:orientation=&quot;horizontal&quot;
        android:layout_alignParentBottom=&quot;true&quot;
        android:id=&quot;@+id/lytFooter&quot;&gt;

        &lt;ImageView
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:id=&quot;@+id/btnPrevious&quot;
            app:srcCompat=&quot;@drawable/left_arrow_shadow&quot;
            android:layout_margin=&quot;1dp&quot;
            android:layout_gravity=&quot;center_vertical&quot;
            android:background=&quot;@drawable/lightbutton_selector&quot;
            android:focusable=&quot;true&quot;/&gt;

        &lt;TextView
            android:id=&quot;@+id/txtBottom&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;@string/look_around&quot;
            android:textAppearance=&quot;?android:attr/textAppearanceLarge&quot;
            android:layout_weight=&quot;1&quot;
            android:layout_gravity=&quot;center_vertical&quot;
            android:gravity=&quot;center_horizontal&quot;
            style=&quot;@style/CameraText&quot; /&gt;

        &lt;ProgressBar
            style=&quot;?android:attr/progressBarStyleHorizontal&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:id=&quot;@+id/prgVideoMode&quot;
            android:layout_weight=&quot;1&quot;
            android:layout_gravity=&quot;center_vertical&quot;
            android:gravity=&quot;center_horizontal&quot;
            android:max=&quot;100&quot; /&gt;

        &lt;ImageView
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:id=&quot;@+id/btnNext&quot;
            app:srcCompat=&quot;@drawable/left_arrow_shadow&quot;
            android:layout_margin=&quot;1dp&quot;
            android:layout_gravity=&quot;center_vertical&quot;
            android:background=&quot;@drawable/lightbutton_selector&quot;
            android:focusable=&quot;true&quot;
            android:clickable=&quot;true&quot;/&gt;

    &lt;/LinearLayout&gt;

&lt;/RelativeLayout&gt;
</code></pre>
<p>The full stracktrace is 80 lines long so I posted it here if you are interested: <a href="http://pastebin.com/RWa91G63" rel="nofollow noreferrer">http://pastebin.com/RWa91G63</a></p>