Getting NoMatchingViewException during perform(…), but not the preceding check(…)

Issue

I have this simple Espresso interaction:

onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
                .check(matches(allOf(isDisplayed(), isEnabled())))
                .perform(typeText("1"));

The check(matches(allOf(isDisplayed(), isEnabled()))) passes as expected, but the following perform(typeText("1")) does not. I cannot figure out why, for the life of me.

So, I can’t believe I’m asking this, but how in the name of Android do I use Espresso to type text into my EditText whose ID is R.id.editTextTextWidget?

Solution

I fixed the problem by splitting the check(...) call and perform(...) call:

onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
        .check(matches(allOf(isDisplayed(), isEnabled())));
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
        .perform(typeText("1"));

For some reason this works, and the original doesn’t. #GooglePlz

Answered By – oaskamay

Leave a Comment