Skip to content Skip to sidebar Skip to footer

Espresso - Typetext Not Working

I'm trying to type some text inside an EditText: public void testSearch() { onView(withId(R.id.titleInput)).perform(typeText('Engineer')); onView(withId(R.

Solution 1:

Looks like I figured out the issue. It had to do with hardware vs software keyboard.

For Emulators:

Go to Settings -> Language & Input -> switch the Default Input to Sample Soft Keyboard.

For Phones:

Install a software keyboard from the Play store and switch to it. It appears that the native keyboards of some phones do not work.

It works now.

Solution 2:

Had the same issue using Espresso 2. As a workaround I'm using replaceText instead of typeText.

public void testSearch() {
      onView(withId(R.id.titleInput)).perform(click(), replaceText("Engineer"));
      onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}

Solution 3:

If the EditText does not has the focus yet, you should click on it first. If this solves your problem, then there is no bug.

onView(withId(R.id.titleInput)).perform(click()).perform(typeText("Engineer"));

Solution 4:

You can bypass the problem by calling setText on the EditText.

finalEditTexttitleInput= (EditText) activity.findViewById(R.id.titleInput);
   getInstrumentation().runOnMainSync(newRunnable() {
        publicvoidrun() {
            titleInput.setText("Engineer");
        }
    });

Solution 5:

Same issue resolved with the following:

editText.perform(scrollTo(), click(), clearText(), typeText(myInput), closeSoftKeyboard())

Interestingly, I only ever had a problem when my machine was working hard.

Post a Comment for "Espresso - Typetext Not Working"