一、查找"孙元素"
如:<RelativeLayout
android:id="@+id/rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="rl" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
通过rl获取btnOk:
UiObject rl=new UiObject(new UiSelector().description("rl"));
UiObject btnOk=rl.getChild(new UiSelector().className(Button.class));
要点: UiObject.getChild可获取孙元素(其实可以是任何层次)