Appium用send_keys输入内容后想模拟键盘搜索按钮,网上找了方法没法实现
代码:
self.driver.find_element(MobileBy.ID, “search”).click()
self.driver.find_element(MobileBy.ID, “etSearch”).send_keys(“201901”)
self.driver.keyevent(66) #模拟Enter键
搜索按钮无法点击的解决办法
- driver.execute_script(“mobile:performEditorAction”,{‘action’:‘search’})
- 原理(官网说明):
driver.execute_script方法支持的命令之一
mobile:performEditorAction
具体用法为:driver.execute_script("mobile:performEditorAction",{'action':action名称})
在焦点输入区域内执行给出的编辑器动作。支持的action名称如下: normal, unspecified, none, go, search, send, next, done, previous
- 还有一种比较笨但是更通用的办法,使用坐标点击,先获取屏幕尺寸之后,对照搜索按钮的位置调整坐标使用点击动作来点击搜索按钮的大概坐标,也可以完成搜索操作
1 个赞