Appium 如何不清空 EditText 原内容继续输入

林茵 · 2014年12月28日 · 最后由 回复于 2016年08月17日 · 1928 次阅读

环境
appium:1.3.4.1
语言:java
手机操作系统:android4.4.4
需求
不清空原 EditText 内容,继续输入内容
目前尝试
1.

findElementByXPath("//android.widget.EditText").sendKeys("测试");
findElementByXPath("//android.widget.EditText").sendKeys("a");

结果
第二次 sendKeys("a"),会清空原输入内容"测试"再输入"a"

2.

findElementByXPath("//android.widget.EditText").sendKeys("测试");
findElementByXPath("//android.widget.EditText").click();
findElementByXPath("//android.widget.EditText").sendKeys("a");

结果
还是会清空原输入内容

本人菜鸟中的菜鸟,请大神们指导一下这个要咋整😭

共收到 14 条回复 时间 点赞

负责任的告诉你,不清除是不可能的,死了这个心吧!so ,现在说一下你的需求,我们可以绕道实现之

#1 楼 @zhycbd 底层在实现的时候就先删除了。 你可以先获取,然后拼接在输入。

你可以先把 EditText 里面的 value 取出来放到一个 string 里, 最后你 click 后 sendkeys 传一个新的 String 这个 String 你自己拼个新的 value+ " 你想输入的" 试试

我记得之前有个同学发帖子提过自己扩展 appium 来实现

只能拓展重写 sendkeys 方法了吧。 appium 里 sendkeys 方法中,执行 input 之前就是有 clear 操作的。

#1 楼 @zhycbd
恩,谢谢大神们的回复~~
具体需求是酱纸的
EditText 是一个自动匹配搜索栏来的,需要测试依据输入内容自动调整搜索结果的,包括继续输入、及回删,回删的晓得怎么整了,但是这个继续输入就是不晓得咋整

比如:
环境前提:存在 “测 a"、测 b”
1.输入"测 “,自动显示搜索结果为” 测 a"、“测 b"
2.继续输入"a",自动调整显示搜索结果为” 测 a"

采用 adb input 命令输入,input text,input keyevent 输入字符

#7 楼 @xuxu 这要要注意焦点是否正确,可以在前面添加一个 tap 坐标点击到 ExitText 框的最右边→_→

@weamylady 在定位焦点时,比较懒的做法是可以这么做,不管焦点定位在什么点,可以使用右移光标的 keyevent,循环的次数可以根据输入内容的长短确定,次数尽量可以多些。光标又移的命令:adb shell input keyevent 22。

林茵 #10 · 2014年12月29日 Author

#7 楼 @xuxu
input text 好像不支持中文输入,英文数字是可以的,试过把中文转成 unicode 字符再 input 也不行

觉得还是先存在一个临时变量里比较靠谱

#1 楼 @zhycbd 你好,我想问下我就想在 app 的登陆界面进行登陆的测试,输入不同的账号密码,然后删除再来。但是我们的 app 用户名密码里边有默认的提示信息,sendkey 执行的时候一直想要删除提示信息,我看 appium 上的 info,各种方法全试过了,得出一个结论删不掉,有可能是提示信息,才进行信息的输入,这个过程非常的慢。这个问题怎么解决啊

#1 楼 @zhycbd appium 的提示信息如下:

info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiDevice" to enable field "mUiAutomationBridge"
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiAutomatorBridge" to enable field "mInteractionController"
info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by selecting all and deleting.
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiDevice" to enable field "mUiAutomationBridge"
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiAutomatorBridge" to enable field "mInteractionController"
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController
info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by sending delete keys.
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.UiAutomatorBridge
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: 123

请问楼主,你这个问题最后是采用哪种方法解决的呀,我现在也遇到同样的问题,但我是初学者,不知道具体用哪种方法能解决呀

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册