首先 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


↙↙↙阅读原文可查看相关链接,并与作者交流