常用查找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. spring与mybatis

  2. Android开发实战之底部Dialog弹出效果

    在Android开发中,有很多情况下我们需要使用到对话框,遗憾的是,安卓自带的对话框样式不能满足我们实际的需要,所以往往需要我们自定义对话框,具体做法:写一个对话框继承自Dialog实现他的一个构造方 ...

  3. MYSQL中GROUP BY的细节及SELECT语句顺序

    一.GROUP BY语句的细节 我们知道,在sql中,GROUP BY语句主要用来给数据分组,以便能对每个组进行聚集计算,但是GROUP BY也有一些限制需要知道: 1. GROUP BY字句可以包含 ...

  4. Openssl s_server命令

    一.简介 s_server是openssl提供的一个SSL服务程序.使用此程序前,需要生成各种证书.本命令可以用来测试ssl客户端,比如各种浏览器的https协议支持 二.语法 openssl s_s ...

  5. java的web.xml中<url-pattern>配置[转]

    <servlet-mapping> <servlet-name>downLoadFile</servlet-name> <url-pattern>*.l ...

  6. msyql中子查询IN,EXISTS,ANY,ALL,SOME,UNION介绍

    1.ANY关键字 假设any内部的查询语句返回的结果个数是三个,如:result1,result2,result3,那么, select ...from ... where a > any(.. ...

  7. 如何将.pem转换为.crt和.key

    如何将.pem转换为.crt和.key? 摘自: https://vimsky.com/article/3608.html 貔貅 技术问答 2017-10-08 23:11 certifica ...

  8. 遍历properties文件

    Properties pro = new Properties();try {    InputStream inStr = ClassLoader.getSystemResourceAsStream ...

  9. Java编程规范参考

    谷歌Java编程规范-原版 谷歌Java编程规范-中文翻译版 阿里巴巴Java编程规范 阿里巴巴Java编程规范-IDEA 插件 阿里巴巴Java编程规范-Eclipse 插件

  10. 数据库工具链接阿里云MySQL数据库

    数据库工具:Toad for MySQL ssh工具:XShell 5 跳板机配置: 配置通道: 源主机:数据库工具链接的地址: 侦听接口:数据库工具侦听接口: 目标主机:数据库阿里云地址: 目标端口 ...