Appium 使用 edittext.send_keys()方法,输入值与预期不符合

Rasul · 2014年05月06日 · 最后由 隔壁小王 回复于 2015年08月03日 · 1203 次阅读

如题:
使用 xpath 成功定位到 EditText 之后,想输入"72419596",但实际输入的确是"772419596".
请各位帮忙看一下.
1.是什么导致了这个问题?
2.如何解决?

脚本代码如下:

edittext = driver.find_element_by_xpath('//EditText[@text="用户名"]')
edittext.send_keys("72419596")

Appium 执行 Log 如下:

info: Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"52d757a0-1cf3-4c1c-bbad-9d780b54311e"}
POST /wd/hub/session/52d757a0-1cf3-4c1c-bbad-9d780b54311e/element 200 521ms - 109b
debug: Appium request initiated at /wd/hub/session/52d757a0-1cf3-4c1c-bbad-9d780b54311e/element/2/value
debug: Request received with params: {"sessionId":"52d757a0-1cf3-4c1c-bbad-9d780b54311e","id":"2","value":["7","2","4","1","9","5","9","6"]}
info: Pushing command to appium work queue: ["element:setText",{"elementId":"2","text":"72419596"}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"2","text":"72419596"}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: setText
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
info: Responding to client with success: {"status":0,"value":true,"sessionId":"52d757a0-1cf3-4c1c-bbad-9d780b54311e"}
共收到 6 条回复 时间 点赞

试试不要一次性输入,将字符串拆开一个个输入~

#1 楼 @qddegtya
我改成 edittext.send_keys("7") 试过了, 直接就输入 77....
不论我输入什么,首字符始终会输入 2 次的.

我刚才用的红米手机.. 换成三星的就没事儿了.

我看到的 xpath 都很长,我想知道你这个 xpath 是怎么获取的

#3 楼 @chungeguo
我也是昨天刚接触 xpath 在http://www.w3school.com.cn,就这样写了看了下用法
这样写是能定位到的.

找到你的 ID 不容易哈

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