记录 2018-08-08 该东西只是记录,方便你我他
UiDevice 此类介绍:
打开某个APP
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
try {
UiObject x = mDevice.findObject(new UiSelector().text("中国农业银行"));
x.click();
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
//UiDevice 方法大致介绍
mDevice.pressBack();//模拟手机回退键
mDevice.pressHome();//模拟手机Home键
mDevice.pressMenu();//模拟手机菜单键
mDevice.pressRecentApps();//模拟手机任务栏
... //刻根据业务需求来加自己业务上的东西
工具介绍
uiautomatorviewer.bat
在其目录为:
D:\Android\SDK\tools\bin
下
页面为这个样子的:
UiObject uiObject = new UiObject(new UiSelector().resourceId("com.android.systemui:id/recent_app_clear"));
if (uiObject.exists()) {
uiObject.click();
}
// 在该页面查找ID为:com.android.systemui:id/task_view_thumbnail 的控件
UiObject uiObject = new UiObject(new UiSelector().resourceId("com.android.systemui:id/recent_app_clear"));
//该控件是否存在
if (uiObject.exists()) {
//模拟点击该控件
uiObject.click();
}
UiObject weixin= new UiObject(new UiSelector().text("微信").className("android.widget.TextView"));
//判断是否存在
if (weixin.exists()) {
//模拟点击
weixin.click();
break;
}
UiObject duanxin= new UiObject(new UiSelector().resourceId("com.zui.mms:id/recipient_text_view"));
//判断是否存在
if (duanxin.exists()) {
//模拟点击
duanxin.setText("你要输入的Text");
break;
}
第一种方法
UiObject uiObject = new UiObject(new UiSelector().resourceId("com.zui.filemanager:id/fileListView"));
UiObject child = uiObject.getChild(new UiSelector().className("android.widget.LinearLayout").resourceId("com.zui.filemanager:id/background").index(1));
UiObject child1 = uiObject.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
UiObject child2 = child1.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
UiObject child3 = child2.getChild(new UiSelector().className("android.widget.TextView").index(0).resourceId("com.zui.filemanager:id/file_name"));
if (child3.exists()) {
child3.click();
}
UiObject view1 = new UiObject(new UiSelector().className("android.view.View").instance(24));//数字表示你数的位置
UiObject view2 = new UiObject(new UiSelector().className("android.view.View").instance(25));//数字表示你数的位置
for(int i = 0;i<100;i++){
String test = "";
UiObject view1 = new UiObject(new UiSelector().className("android.view.View").instance(24));
UiObject view2 = new UiObject(new UiSelector().className("android.view.View").instance(25));
try {
test = view1.getText();
if(test == null || test.isEmpty()){
test = view1.getContentDescription();
}
}catch(Exception e){
test = view1.getContentDescription();
}
Log.e("输出", "auditOrder: " + "该元素名称为:" + test + "该元素位置为:" + i );
}
UiDevice.getInstance().click(x,y)
//执行该命令获取页面元素为xml
adb shell /system/bin/uiautomator dump /data/local/tmp/liukangUi.xml
//返回该提示代表成功:dump: creates an XML dump of current UI hierarchy
//推送到电脑
adb pull /data/local/tmp/liukangUi.xml D:\Xml