常用查找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. elasticsearch must和should组合查询

    {"query": { "bool": { "should": [ {"bool": { "must" ...

  2. ubuntu下面板上无网络连接的图标

    解决方法:删除旧的网络配置,重新让networkManager自动配置 sudo service network-manager stop sudo rm /var/lib/NetworkManage ...

  3. centos7的vsftpd的安装和配置

    安装vsftpd的服务器相关软件 安装vsftpd服务器和客户端 sudo yum install ftp vsftpd 安装一个加密工具 sudo yum install libdb-utils.x ...

  4. Nginx通过CORS实现跨域

    Nginx通过CORS实现跨域 2016-09-01 10:33 阅读 9.4k 评论 0 社区广播:运维派(Yunweipai.com)是国内最早成立的IT运维社区,欢迎大家投稿,让运维人不再孤寂的 ...

  5. css3中的transform、transition、translate、animation(@keyframes)的区别

    一.前言 在CSS中,我们经常会使用到transform.transition.translate.animation(@keyframes)这些长得相似,又不好区分的属性(值).每当需要使用它们,都 ...

  6. 关于dojo自定义类

    dojo自定义类时,只要没有在constructor函数中传参改变的变量,都属于静态变量,因此不能用this.访问,而是直接用变量名访问

  7. 游戏动作师使用Unity3D遇到过的所有问题

    http://blog.csdn.net/onafioo/article/details/50865169 http://www.gameres.com/thread_480489.html 文/拉撒 ...

  8. ubuntu16.04 安装opencv3

    (opencvC++) luo@luo-ThinkPad-W540:20181205$ conda install --channel https://conda.anaconda.org/menpo ...

  9. ReactNative常用第三方控件

    Flex可视化在线工具 http://the-echoplex.net/flexyboxes/?fixed-height=on&legacy=on&display=flex&f ...

  10. office excel 2010 破解版下载地址

    office excel 2010 破解版下载地址  http://www.xitongzhijia.net/soft/24189.html