Appium [求助] 使用 sendkeys 方法发送文本时会出现重复输入的情况

无所谓 · 2017年01月05日 · 最后由 小小测试 回复于 2017年08月28日 · 1605 次阅读

各位大神们,本人刚刚入门自学移动端自动化测试,在编写代码过程中出现标题所述问题,一直找不到解决方法,请求各位大神帮助
测试环境应用
appium 版本 1.4.16.1
系统:Win7X64
jar 包版本:java-client-4.0.0,selenium-java-2.53.0
安卓模拟器为 Nexus 5 ,安卓版本为 5.1.1,API 22
使用 JAVA 语言,首先设置默认键盘已经设置
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
输入语句如下,其中 driver 定义的是 AndroidDriver
driver.findElementById("com.ccz.insure:id/et_car_owner_id_number").clear();
driver.findElementById("com.ccz.insure:id/et_car_owner_id_number").sendKeys("510623198408133813");
我将以上语句转换成 web 后实验也不行,log 信息如下,发送的 510623198408133813,在 APP 上面显示出来的是 551062311988408138813

info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by selecting all and deleting.
info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by sending delete keys.
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: <-- POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element/4/clear 200 21608.356 ms - 76 {"status":0,"value":true,"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: --> POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element {"using":"id","value":"com.ccz.insure:id/et_car_owner_id_number"}
info: [debug] Waiting up to 30000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.ccz.insure:id/et_car_owner_id_number","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.ccz.insure:id/et_car_owner_id_number","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.ccz.insure:id/et_car_owner_id_number using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.ccz.insure:id/et_car_owner_id_number]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"5"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"5"},"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: <-- POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element 200 131.033 ms - 87 {"status":0,"value":{"ELEMENT":"5"},"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: --> POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element/5/value {"id":"5","value":["510623198408133813"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"5","text":"510623198408133813","replace":false,"unicodeKeyboard":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"5","text":"510623198408133813","replace":false,"unicodeKeyboard":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Using element passed in.
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
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: 510623198408133813
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: <-- POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element/5/value 200 8248.934 ms - 76 {"status":0,"value":true,"sessionId":"5e45f4aa-e642-4a74-8ab9-372c0f005d54"}
info: --> POST /wd/hub/session/5e45f4aa-e642-4a74-8ab9-372c0f005d54/element {"using":"id","value":"com.ccz.insure:id/et_car_owner_tel"}
info: [debug] Waiting up to 30000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.ccz.insure:id/et_car_owner_tel","context":"","multiple":false}]

共收到 5 条回复 时间 点赞

版本太低了吧,先升级试下

#1 楼 @lose 哪一个版本太低?是 jar 包还是 API?

也有可能是输入法,你可以看看输入法

#3 楼 @ws96apt 已经重置成了默认键盘,输入任然有问题
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");

楼主,你这个问题解决没有啊,我遇到的问题跟你有点相似;但是我的问题造成原因是:调用 sendkeys 的时候会先在文本框点击两次,到第三次的时候才会开始输入,所以前面两次点击会把光标位置移到几个字符之间。一直不知道怎么解决啊

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