我使用android版本4.4.2和python 2.7进行UI自动化。
当我尝试使用UI automator/culebra/dump捕获视图时,我无法捕获QWERTY键盘视图。请帮我处理这个
我需要触摸和键入qwerty键盘,我应该能够键入字母数字文本和微笑。同样,一旦键入,您应该验证屏幕上显示的内容是否是您想要键入的内容。
提前谢谢。
正如另一个答案所提到的,使用UiAutomator后端的AndroidViewClient无法转储主窗口之外的任何其他窗口的内容,因此无法访问输入法窗口。
AndroidViewClient支持其他后端,如ViewServer。您可以查看AndroidViewClient源代码提供的示例,特别是在dump-all-windows.py中,它显示了如何转储其他窗口的内容,而不仅仅是主窗口的内容。尽管您可以在键盘上获得大多数视图,但实际的键是由com.android.inputmethod.keyboard.internal.PreviewPlacerView
内部处理的,因此您无法单独与它们交互。
记住,你总是可以像在中一样使用它们的坐标来触摸按键
if device.isKeyboardShown():
device.touch(400, 950)
这将触及768x1280模拟器上的G。但这取决于设备。
QWERTY键盘是webview,UiAutomator目前不支持webview。AndroidViewClient基于UiAutomator,因此不捕获键盘。
如果您的目标只是键入文本,则可以首先检测焦点是否在文本字段上,然后使用device.type('your_text')
。
如果要从键盘上按字符,请使用:
getDevice().pressKeyCode(KeyEvent.<KeyCode>)
KeyCode可以从以下位置获得:http://developer.android.com/reference/android/view/KeyEvent.html但在执行此操作之前,您需要将字符串转换为字符,并传递每个字符以获得相应的KeyEventCode。
can perform:
typeInDevice("Any text")
or
typeInView("ViewId/content/text where you want to enter text","Any text")
device accessibility can be as your requirement ..
self.typeInDevice()
or
vc.typeInDevice()
Verification :
isKeyboardShown(): can be used for verifying that the keyboard
is appeared.
the entered text can be retrieved by using gettext() and same can be
compared with the entered value.