Click on EditText's drawable right with Espresso

前端 未结 4 728
小鲜肉
小鲜肉 2021-02-10 00:54

How could be possible to click on EditText\'s right drawable (check the screenshot)? I have tried several ways but I always get stuck.

public static Matcher

        
4条回答
  •  耶瑟儿~
    2021-02-10 01:30

    For people that have this problem right now as of 1/7/2021 (European format). I had the same problem and solved it like this:

    In your xml, maybe you have something like this:

    
    
        
    
    
    

    As you saw the above xml code, i added app:endIconContentDescription="clear text". grab from the xml, app:endIconContentDescription="clear text" and add onView(withContentDescription("clear text")).perform(click()); in your Instrumented test method, in your test class, like:

        @Test
        public void testEdittext(){
        onView(withId(R.id.eddittext)).perform(typeText("Type something."));
        onView(withContentDescription("clear text")).perform(click());
        }
    

    Forgot to say that this onView(withId(R.id.note_title)).perform(typeText("Type something.")); is the line that you must first write something in the edittext, so that the end icon(eddittext's right drawable) will show up and then click it.

提交回复
热议问题