ADB转储视图层次结构与Android Studio中的UiAutomator不同?

时间:2018-05-29 05:58:10

标签: android android-studio adb ui-automation uiautomator

我试图使用其resourceId获取第三方Android应用中的元素。当我使用命令adb shell uiautomator dump时,XML视图层次结构显示了我正在寻找的元素。但是,当我在使用UITest运行UITest时尝试在Android Studio中使用UiAutomator获取元素时 device.findObject(new UiSelector().resourceId(myResourceID)),没有这样的元素。

有什么会导致这种行为吗?我对Android很新,所以如果我需要提供更多细节,请告诉我。谢谢!

1 个答案:

答案 0 :(得分:0)

无法从您发布的信息中提取问题的原因。转储之间可能存在差异。

但是,culebra.dtmilano.com可能对您的情况有帮助,因为您可以直接在树上选择视图,如此处所示(将鼠标悬停在“设置”上)

enter image description here

生成

和相应的Java(在本例中)或Python,Kotlin等代码,确保View的选择器是正确的

@Test
public void culebraGeneratedTest() throws Exception {
    mDevice.findObject(By.desc("Settings").clazz("android.widget.TextView").text("Settings").pkg("com.google.android.apps.nexuslauncher")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}