【Appium】:解决EditText空间无法使用方法clear()完全清除内容

在使用java_client的方法clear() 清除EditText的内容是,无法完全清除完,采用clear()方法,清空内容的效果如下:

 

所以自己封装一个clearText()的方法来清空,清空步骤分为四步:

1,选中元素;

2,光标移动到最后;

3,ctrl+A 全选所有内容;

4,回车清除所有内容;

将2-4步封装成clearText()方法

    public  void clearText(String text) {
        driver.pressKeyCode(AndroidKeyCode.KEYCODE_MOVE_END);
     driver.pressKeyCode(AndroidKeyCode.KEYCODE_A,AndroidKeyCode.META_CTRL_MASK);
        driver.pressKeyCode(AndroidKeyCode.BACKSPACE);
    }

 执行调用clearText()

 

        List<MobileElement> InputName_text = (List<MobileElement>) driver.findElementsByClassName("android.widget.EditText");
        String InputName_text_content = InputName_text.get(0).getAttribute("name");
        System.out.println(InputName_text_content);
        InputName_text.get(0).click();
        clearText(InputName_text_content);
        //this.InputName_text.clear();
        InputName_text.get(0).sendKeys("dingwen");

 

 

posted @ 2019-07-17 10:06  fy-  阅读(577)  评论(0)    收藏  举报