Espresso - typeText not working

前端 未结 10 1086
名媛妹妹
名媛妹妹 2021-02-13 22:20

I\'m trying to type some text inside an EditText:


    public void testSearch() {
          onView(withId(R.id.titleInput)).perform(typeText(\"Engineer\"));
          


        
相关标签:
10条回答
  • 2021-02-13 22:33

    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.

    0 讨论(0)
  • 2021-02-13 22:33

    I fixed this issue by setting layout_height="wrap_content" on the View I wanted to click(). Maybe it can help someone here.

    0 讨论(0)
  • 2021-02-13 22:35

    If you're using Genymotion, you may need to switch the default keyboard in Genymotion Configuration (it's an app on the emulator).

    1. Go to Apps -> Genymotion Configuration -> Keyboard -> Virtual keyboard (click "Yes" when you're prompted to reboot)

    NOTE: These changes do not persist after you close the emulator. You will need to set this every time you start the emulator.

    0 讨论(0)
  • 2021-02-13 22:35

    Adding closeSoftKeyboard() after typeText() worked for me.

    CODE:

    onView(withId(R.id.editTextUserInput))
                .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
    

    This is how it is documented in the Android docs.

    0 讨论(0)
  • 2021-02-13 22:37

    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.

    0 讨论(0)
  • 2021-02-13 22:37

    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"));
    
    0 讨论(0)
提交回复
热议问题