Appium:清除字段 [英] Appium : Clear a field

查看:111
本文介绍了Appium:清除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在应用程序中有我的登录屏幕.每次在屏幕上启动该应用程序时,手机号码都会预先填充较旧的文字.

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:

WebElement mob = driver.findElement(By.name("Mobile Number"));
mob.clear // Not working

我尝试过:

String Mobile
mob="";   

但仍然无法删除预填充的文本.

but still it cannot delete the pre filled text.

我正在尝试使用appium自动化我的android应用程序,请为此提供帮助.

I am trying to automate my android app using appium, please help me with this.

推荐答案

它肯定不是有效的,可以加以改进,并且可能有更好的方法... 但是,使用adb的shell输入键事件代码,我只是简单地称为"dpad right",将光标一直向右移动.到达那里后,发送键码"DEL"以开始一路删除... 所以...两个for循环.这主要用于短文本:

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是AppiumDriver实例. 希望这对您有所帮助.

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

这篇关于Appium:清除字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆