uiautomator2+python-模拟安卓键盘输入
uiautomator2+python-模拟安卓键盘输入
·
uiautomator2+python-模拟安卓键盘输入
-
这种方法通常用于不知道控件的情况下的输入。第一步需要切换输入法,然后发送adb广播命令,具体使用方法如下d.set_fastinput_ime(True)
-
先清除掉文本框的内容
-
d.press(“back”)为收起键盘,可能存在键盘阻挡住别的页面元素,需要收起键盘
d = u2.connect()
d.set_fastinput_ime(True)
d.clear_text()
d.send_keys(text, True)
print("输入文本: " + text)
d.press("back")
- 如果需要进行搜索按钮 需要使用到此处的函数:send_action
d = u2.connect()
d.set_fastinput_ime(True)
d.clear_text()
d.send_keys("测试", True)
print("输入文本: " + "测试")
d.set_fastinput_ime(False) # 切换成正常的输入法
d.send_action("search") # 模拟输入法的搜索
- 有些时候在EditText中输入完内容之后,调用press(“search”) or press(“enter”)发现并没有什么反应。 这个时候就需要send_action函数了, send_action先broadcast命令发送给输入法操作IME_ACTION_CODE,由输入法完成后续跟EditText的通信。
更多推荐
已为社区贡献1条内容
所有评论(0)