Appium : Clear a field

后端 未结 26 3183
野趣味
野趣味 2020-12-16 16:03

I have my login screen in app now. Each time the app is launched in screen the mobile number is pre filled with the older text.

I just want to know I have tried:

26条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 16:51

    It is definitely not efficient, could be improved and there's probably a better way... But, using adb's shell input key event codes I simply called "dpad right" to move the cursor all the way to the right. Once there, send the key code "DEL" to start deleting all the way back... So... two for-loops. This was mainly used for short texts:

    public void cleatTextFully(WebElement element) {
        int stringLength = element.getText().length();
    
        for (int i = 0; i < stringLength; i++) {
            mDriver.sendKeyEvent(22); // "KEYCODE_DPAD_RIGHT"
        }
    
        for (int i = 0; i < stringLength; i++) {
            mDriver.sendKeyEvent(67); // "KEYCODE_DEL"
        }
    }
    

    mDriver is the AppiumDriver instance. Hope this helps some what.

提交回复
热议问题