Appium appium 1.3.4.1 版 sendkey 错误

adfghzhang · March 19, 2015 · Last by 陈恒捷 replied at March 19, 2015 · 1631 hits

有没有人遇到 appium1.3.4.1 版 sendkey 的时候删除原值再 send 时,文本框的最后结果为:原值 +send 值的情况
例如:日历插件输入框中日期为 2015-03-19,要输入 2015-03-20,先 clear 文本框,再 sendkey("2015-03-20")。其结果为 2015-03-192015-03-20。查看 appium 日志也显示发送的有问题。Sending plain text to element: 2015-03-192015-03-20
在 1.2.4 版无这样的情况,但是 1.2.4 版 sendkey 速度非常慢。
代码:

driver.SendKeyByElement(pageOrderQuery.text_order_depdate,2015-03-20);

日志:

> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding com.*.*.*:id/custom_date_input_edittext_edittext using ID with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.*.*.*:id/custom_date_input_edittext_edittext]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"20"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"20"},"sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: <-- POST /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element 200 51.130 ms - 88 {"status":0,"value":{"ELEMENT":"20"},"sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: --> GET /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/text {}
> info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"20"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"20"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getText
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"2015-03-19","status":0}
> info: [debug] Responding to client with success: {"status":0,"value":"2015-03-19","sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: <-- GET /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/text 200 575.271 ms - 84 {"status":0,"value":"2015-03-19","sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: --> GET /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/text {}
> info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"20"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"20"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getText
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"2015-03-19","status":0}
> info: [debug] Responding to client with success: {"status":0,"value":"2015-03-19","sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: <-- GET /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/text 200 418.224 ms - 84 {"status":0,"value":"2015-03-19","sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: --> POST /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/value {"id":"20","value":["2015-03-20"]}
> info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"20","text":"2015-03-20","replace":false,"unicodeKeyboard":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"20","text":"2015-03-20","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] 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] Finding methods on class: class com.android.uiautomator.core.InteractionController
> 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] Sending plain text to element: 2015-03-192015-03-20
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
> info: <-- POST /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/value 200 13211.567 ms - 76 {"status":0,"value":true,"sessionId":"4adf2a57-f5d7-4c32-9f2d-64621d825d7a"}
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 7 条回复 时间 点赞

从日志上看,有可能是这里出的问题:

Pushing command to appium work queue: ["element:setText",{"elementId":"20","text":"2015-03-20","replace":false,"unicodeKeyboard":true}]

此处的"replace":false可能会让 sendKeys 在原有字符在不清空的情况下继续输入。

@tspring 能否帮忙让你们组相应组员查查 BOOTSTRAP 这边对于"replace":false实际是怎么执行的?
我们组这边会看看 1.3.4.1 的 Server 端在

> info: --> POST /wd/hub/session/4adf2a57-f5d7-4c32-9f2d-64621d825d7a/element/20/value {"id":"20","value":["2015-03-20"]}
> info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"20","text":"2015-03-20","replace":false,"unicodeKeyboard":true}]

这两行日志之间根据什么设定replace的。

另外,@adfghzhang 能否提供一下你使用的 client 的语言和版本?谢谢。

PS:我这边使用 python 的 Appium-Python-Client==0.11 作为客户端,Appium 1.2.0 作为服务端,真机使用 Android 4.3,使用 send_keys() 方法会清空输入框后再输入。

刚刚用 appium 1.3.4.1 的 exe 试了一下(使用 python client):

username = self.driver.find_element_by_id("xxx")
username.send_keys("test")
username.send_keys("abcdefg")

执行完后 username 框的内容为"testabcdefg"
改为:

username = self.driver.find_element_by_id("xxx")
username.send_keys("test")
username.clear()
username.send_keys("abcdefg")

执行完后 username 框的内容为"abcdefg"
@adfghzhang 你可以试试加上 clear() 方法。

@chenhengjie123 语言环境 java,client 版本 2.1.0。

实际执行的效果是:原文本框有 2015-03-19,调用 send 方法也是清空了文本框的值的,但最后结果就是输入了 2015-03-192015-03-20

最近我在三星设备上面遇到丢失按键的情况,比如 ‘123456’,实际输入为 ‘23456’,其它设备不存在这个问题

#5 楼 @misnull 我也遇到过,貌似三星的默认输入法映射有点问题,后来改成用 google 拼音输入法就好了。
对于非 ASCII 字符(如中文),目前只有 Appium 的 unicode 输入法一条路。坏处是它触发不了输入法的按键事件(因为它压根就没按键,直接传信号的)

#4 楼 @adfghzhang 有试过像我那样在 sendKeys 前先 clear 吗?效果如何?

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up