Appium 关于 Python+Appium 1.2.2 版本,Android 上 element.clear()方法清除 edit field 报错的处理办法

Alex · 2014年09月12日 · 1596 次阅读

首先 clear(), send_keys(), set_text(),在 android 上不太好用是个已知的 bug(在 IOS 上不清楚,没有测试环境),会在 Appium 1.2.3 上修复。请参见 github 的 issue:https://github.com/appium/python-client/issues/53

在这之前我们可以用 press_keycode 的方式实现删除,删除速度比忽略 clear() 抛出的异常要快很多。
大概思路是:
1. 点击要清除的 edit field
2. 全选
3. 删除

element.click()
sleep(1)   #waiting for 1 second is important, otherwise 'select all' doesn't work. However, it perform this from my view
self.driver.press_keycode(29,28672)   # 29 is the keycode of 'a', 28672 is the keycode of META_CTRL_MASK
self.driver.press_keycode(112)   # 112 is the keycode of FORWARD_DEL, of course you can also use 67
共收到 4 条回复 时间 点赞
匿名 #1 · 2014年09月12日

刚在 iOS 上验证了一下,1.2.1 的版本都是好的,1.2.2 有坑就不跳了。。坐等 1.2.3 再说

el = driver.find_element_by_xpath("//UIATextField[@value='www.company.com']")
el.click()
el.send_keys("192.168.1.100")
el.clear()
el.set_value("192.168.2.100") #iOS为set_value()

press_keycode 感觉可读性和可维护性不好.....

Alex #2 · 2014年09月12日 Author

keycode,的确可读性不高,所以目前在 1.2.3 没出来之前可以先用着,一般我都是把 keycode 相关的代码封装起来,呵呵也许只有我自己会读到里面的。。。

赞,这个方法行得通。
试了 1.2.4, clear() 和 send_keys() 仍然有问题。

#2 楼 @ianxiaohanxu 但是封装起来的话也是用 press_keycode 方法吧?

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