protected void setLoadPicture() throws UiObjectNotFoundException { // 点击更多按钮 showMore(); // 选择设置 UiObject settings = new UiObject(new UiSelector().resourceId("android:id/title").text("设置")); settings.clickAndWaitForNewWindow(); // 选择带宽管理 UiObject privacy = new UiObject(new UiSelector().resourceId("android:id/title").text("带宽管理")); privacy.clickAndWaitForNewWindow(); // 勾选加载图片 UiObject list = new UiObject(new UiSelector().className(ListView.class)); for (int i = 0; i < list.getChildCount(); i++) { UiObject ll = list.getChild(new UiSelector().className(LinearLayout.class).index(i)); UiObject tv = ll.getChild(new UiSelector().className(TextView.class).index(0)); if (tv.getText().equals("加载图片")) { UiObject enable = ll.getChild(new UiSelector().resourceId("android:id/checkbox")); if (enable.isCheckable() && !enable.isChecked()) { enable.click(); } break; } } // 返回浏览界面 getUiDevice().pressBack(); getUiDevice().pressBack(); }
/** * 点击搜索框后,输入搜索关键词进行搜索 * * @throws UiObjectNotFoundException */ public void setSearchWord() throws UiObjectNotFoundException { // 点击搜索框 UiObject textV = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/tv_search")); textV.click(); // 判断搜索框是否存在-输入QQ搜索 UiObject textVChild = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/top_search_container")); Assert.assertEquals(true, textVChild.exists()); textVChild.setText("QQ"); sleep(1000); // 获取搜索关键字列表 UiObject listViewOb = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/baselistview")); // Assert.assertEquals(0, listViewOb.getChildCount()); // 点击列表第一个搜索关键字 UiObject childOb = listViewOb.getChild(new UiSelector().index(6)); // childOb.click(); Assert.assertEquals(true, childOb.exists()); if (childOb.exists()) { childOb.clickAndWaitForNewWindow(); } else { UiObject selectButton = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/top_search_container")); selectButton.clickAndWaitForNewWindow(); } }
public UiObject getChild(final UiSelector sel) throws UiObjectNotFoundException { return el.getChild(sel); }