代码
问题:
相同的代码,在 1.6.4 中,send_keys(” 中文 “) 没有反应
在 1.4.16 中能正常输入。这个是什么情况
python 的话 send_keys(u'中文')
加个 u 看看
appium log:JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/e39eaa0e-a094-4e96-bf59-7773f89c6506/element] with body: {"strategy":"id","selector":"com.hk515.patient:id/rm","context":"","multiple":false}
[JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"08319920-91d4-4c11-ba80-fbb4a7fa4c1b"},"status":0,"sessionId":"e39eaa0e-a094-4e96-bf59-7773f89c6506"}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"08319920-91d4-4c11-ba80-fbb4a7fa4c1b"}
[HTTP] <-- POST /wd/hub/session/049c6198-4f40-4cfb-85b0-fc453838041a/element 200 501 ms - 122
[HTTP] --> POST /wd/hub/session/049c6198-4f40-4cfb-85b0-fc453838041a/element/08319920-91d4-4c11-ba80-fbb4a7fa4c1b/value {"id":"08319920-91d4-4c11-ba80-fbb4a7fa4c1b","value":["正啊 kang"]}
[MJSONWP] Calling AppiumDriver.setValue() with args: [["正啊 kang"],"08319920-91d4-4c11-ba80-fbb4a7fa4c1b","049c6198-4f40-4cfb-85b0-fc453838041a"]
[JSONWP Proxy] Proxying [POST /element/08319920-91d4-4c11-ba80-fbb4a7fa4c1b/value] to [POST http://localhost:8200/wd/hub/session/e39eaa0e-a094-4e96-bf59-7773f89c6506/element/08319920-91d4-4c11-ba80-fbb4a7fa4c1b/value] with body: {"elementId":"08319920-91d4-4c11-ba80-fbb4a7fa4c1b","text":"正啊 kang","replace":false,"unicodeKeyboard":true}
[JSONWP Proxy] Got response with status 200: {"value":"","status":0,"sessionId":"e39eaa0e-a094-4e96-bf59-7773f89c6506"}
[MJSONWP] Responding to client with driver.setValue() result: ""
appium 1.4.16 的 log: info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
info: <-- POST /wd/hub/session/e4d10a9d-c40c-4dc5-8720-b7265b803374/element/5/click 200 3890.120 ms - 76 {"status":0,"value":true,"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
info: --> POST /wd/hub/session/e4d10a9d-c40c-4dc5-8720-b7265b803374/element {"using":"id","value":"com.hk515.patient:id/rm"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.hk515.patient:id/rm","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.hk515.patient:id/rm","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.hk515.patient:id/rm using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.hk515.patient:id/rm]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"6"},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"6"},"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
info: <-- POST /wd/hub/session/e4d10a9d-c40c-4dc5-8720-b7265b803374/element 200 34.281 ms - 87 {"status":0,"value":{"ELEMENT":"6"},"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
info: --> POST /wd/hub/session/e4d10a9d-c40c-4dc5-8720-b7265b803374/element/6/value {"id":"6","value":["姝e晩 kang"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"6","text":"姝e晩 kang","replace":false,"unicodeKeyboard":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"6","text":"姝e晩 kang","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 Unicode text to element: 姝e晩 kang
info: [debug] [BOOTSTRAP] [debug] Encoded text: &a2NVSg-kang
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
info: <-- POST /wd/hub/session/e4d10a9d-c40c-4dc5-8720-b7265b803374/element/6/value 200 6771.138 ms - 76 {"status":0,"value":true,"sessionId":"e4d10a9d-c40c-4dc5-8720-b7265b803374"}
备注,输入的其实是中文 value:正啊 kang
set_value 试试
我也碰到过,感觉跟机型有关。最后用自带的方法封装了一个点击输入框的动作,然后在用 adb 命令输入
用 set_text(), selenium 3.4 后 send_keys,就用不了了, 取而代之的是 set_value,输入速度提高了很多,set_text() 用来输入中文