常用查找UiObject方法

// 通过ID查找
public static UiObject findById(String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text));
return appBtn;

}

例如:UiObject search_src_text =findById("com.android.contacts:id/search_view")

// 通过resource和description查找
public static UiObject findByResourceIdAndDesc(String className, String text)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.description(text));
return appBtn;

}

例如:UiObject back_camera = findByResourceIdAndDesc(
"com.android.camera2:id/camera_toggle_button","Play video");

// 按Text Contains定位
public static UiObject findByTextContains(String text) {
UiObject getItem = new UiObject(new UiSelector().textContains(text));
return getItem;

}

例如:UiObject notice = findByTextContains("Remember photo locations");

// 通过resource和index查找
public static UiObject findByResourceIdAndIndex(String className, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
.index(index));
return appBtn;

}

例如:UiObject back_camera = findByResourceIdAndIndex(
"com.android.camera2:id/camera_toggle_button",0);

// 通过ID,instance查找
public static UiObject findByIdInStance(String text, int index)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text)
.instance(index));
return appBtn;

}

例如:UiObject back_camera = findByIdInStance(
"com.android.camera2:id/camera_toggle_button",1);

// 按照className查找UiScrollable;
public static UiScrollable findUiScrollableByClassName(String className)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(
new UiSelector().className(className));
return scrItem;
}

// 通过source和text查找
public static UiObject findByResourceIdAndText(String text1, String text2)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(text1).text(
text2));
return appBtn;

}

例如:UiObject mode = findByResourceIdAndText(
"com.android.camera2:id/selector_text", "text");

// 通过source和text查找
public static UiObject findByResourceIdAndTextContains(String resourceId, String textContains)
throws UiObjectNotFoundException {
UiObject appBtn = new UiObject(new UiSelector().resourceId(resourceId).textContains(
textContains));
return appBtn;

}

例如:UiObject mode = findByResourceIdAndTextContains(
"com.android.camera2:id/selector_text", "text");

// 按照className和index在UiScrollable中查找
public static UiScrollable findUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
UiScrollable scrItem = new UiScrollable(new UiSelector().className(
className).instance(index));
return scrItem;

}

// 获取UiCollection中的子对象的个数
public static int findChildCountFromUiCollectionByClassName(
UiCollection uiCollection, String className)
throws UiObjectNotFoundException {
return uiCollection
.getChildCount(new UiSelector().className(className));
}

// 在UiScrollable中通过className和instance查找
public static UiObject findFromUiScrollableByClassNameAndInstance(
UiScrollable uiScrollable, String className, int index)
throws UiObjectNotFoundException {
return uiScrollable.getChild(new UiSelector().className(className)
.index(index));
}

// 按className定位Scrollable
public static UiScrollable findScrollableByClass(String className) {
return new UiScrollable(new UiSelector().className(className));
}

UiAutoMator一些常用的方法的更多相关文章

  1. WebAPi添加常用扩展方法及思维发散

    前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...

  2. StringUtils中的常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  3. JOptionPane类提示框的一些常用的方法

    JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...

  4. 常用js方法

    function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...

  5. jQuery操作Table tr td常用的方法

    虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...

  6. iOS常用公共方法

      iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...

  7. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  8. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

  9. Java获取各种常用时间方法大全

    Java获取各种常用时间方法大全 package cc.javaweb.test; Java中文网,Java获取各种时间大全 import java.text.DateFormat; import j ...

随机推荐

  1. DataTable相关

    设置主键列:  this.tableTestData.PrimaryKey = new DataColumn[] { this.tableTestData.Columns[0] };

  2. 结对作业——四则运算 Part2. 封装与对接相关问题

    结对作业——四则运算 Part2. 封装与对接相关问题 PB15061303 刘梓轩PB16061489 艾寅中 GITHUB 地址 戳这里 目录 Part 1. Core代码编写部分Part 2. ...

  3. 【HDU1542】Atlantis

    题意 给出n个矩形的左下角和右上角的坐标,计算总的面积(相交部分只算一次). 分析 线段树扫描线的模板题. 将每个矩形都拆成上下两条线段,然后从下网上扫,当遇到底边时就加上这个区间,遇到顶边时,就减去 ...

  4. 解剖Nginx·自动脚本篇(2)设置初始变量脚本 auto/init

    在configure中运行完auto/options脚本后,接着运行auto/init脚本,其中所做的工作如下. 1 Makefile文件名变量 默认情况下是: objs/Makefile 代码如下: ...

  5. Java读取Unicode文件(UTF-8等)时碰到的BOM首字符问题

    在Windows下用文本编辑器创建的文本文件,如果选择以UTF-8等Unicode格式保存,会在文件头(第一个字符)加入一个BOM标识.   这个标识在Java读取文件的时候,不会被去掉,而且Stri ...

  6. activeMQ集群搭建及高可用

    三台服务器搭建如下的集群,达到了高可用.也同时达到了负载的目的: /****************************************************************** ...

  7. 服务器监控方案CactiEZ V10.1

    CactiEZ中文版是最简单有效的Cacti中文解决方案,整合Spine,RRDTool和美化字体.集成Thold,Monitor,Syslog,Weathermap,Realtime,Errorim ...

  8. [C++] How to prevent memory leaks

    How to prevent memory leaks ? overload new/delete

  9. p4475 巧克力王国

    传送门 分析 我们多维护一个值,代表某个点子树中所有点的权值和 于是如果某个点它的min和max乘a(/b)的值小于范围则直接把整个子树都加进去 估价函数就是这个点的子树中的理论最小值 代码 #inc ...

  10. linux环境下搭建osm_web服务器三(Openlays和slippymap):

    Openlays和slippymap 上一步,我们已经有了自己的地图瓦片服务器,现在,开始实现SlippyMap啦! <1>下载释放OpenLayers到 www文件夹 SlippyMap ...