我已经使用 UI Automator 自动转到 android 手机中的设置,我使用“getUiDevice().pressMenu();”单击菜单及其带有 3 个子菜单项的打开菜单,我想使用名称或索引或 ID 单击第二个菜单,请帮助如何单击 Android UIAutomator 中的子菜单?
最佳答案
这个带有三个点的溢出菜单图标 ImageView
没有 id ...
但是可以通过它的描述得到它:
UiObject2 menuButton = this.mDevice.findObject(By.desc("More options"));
/* open the menu */
if(menuButton != null && menuButton.isClickable()) {
menuButton.click();
menuButton.recycle();
} else {
Assert.fail();
}
然后可以按索引单击菜单项:
ArrayList<UiObject2> menu = (ArrayList<UiObject2>) this.mDevice.findObject(By.clazz("android.widget.ListView")).getChildren();
/* click the menu item at index 0 */
UiObject2 menu_action = menu.get(0);
if (menu_action != null && menu_action.isClickable()) {
menu_action.click();
menu_action.recycle();
} else {
Assert.fail();
}
关于android - UIAutomator - 如何点击菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721400/