对象搜索—文本与描述

一、文本属性定位对象:

返回值 API 描述
UiSelector test(String text) 文本完全匹配
UiSelector testContains(String text) 文本包含匹配
UiSelector textMatches(String regex) 文本正则匹配
UiSelector textStartsWith(String text) 文本起始匹配

二、描述属性定位对象:

返回值 API 描述
UiSelector description(String desc) 描述完全匹配
UiSelector descriptionContains(String desc) 描述包含匹配
UiSelector descriptionMatches(String regex) 描述正则匹配
UiSelector descriptionStartsWith(String desc) 描述开始字符匹配

三、API应用举例:

package com.testuiselector;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Demo1 extends UiAutomatorTestCase { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String jarName, testClass, testName, androidId;
jarName="demo1";
testClass="com.testuiselector.Demo1";
testName="testText";
androidId="1";
new UiAutomatorHelper(jarName, testClass, testName, androidId);
} public void testText() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000); UiSelector l1=new UiSelector().text("People");
UiObject people1=new UiObject(l1);
people1.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l2=new UiSelector().textContains("ople");
UiObject people2=new UiObject(l2);
people2.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l3=new UiSelector().textMatches(".*opl.*");
UiObject people3=new UiObject(l3);
people3.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l4=new UiSelector().textStartsWith("peo");
UiObject people4=new UiObject(l4);
people4.click();
sleep(2000); UiDevice.getInstance().pressBack(); } public void testDescription() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000); UiSelector l1=new UiSelector().description("Apps");
UiObject desc1=new UiObject(l1);
desc1.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l2=new UiSelector().descriptionContains("pp");
UiObject desc2=new UiObject(l2);
desc2.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l3=new UiSelector().descriptionMatches(".*pp.*");
UiObject desc3=new UiObject(l3);
desc3.click();
sleep(2000); UiDevice.getInstance().pressBack();
sleep(2000); UiSelector l4=new UiSelector().descriptionStartsWith("Ap");
UiObject desc4=new UiObject(l4);
desc4.click();
sleep(2000); UiDevice.getInstance().pressBack(); } }

Demo1.java

最新文章

  1. 为什么要重写hashcode() 方法
  2. JavaScript 跨域小总结
  3. Android Studio NDK 学习之接受Java传入的字符串
  4. vs 引用sqlite的问题
  5. Linux 命令 - ftp: 网络文件传输工具
  6. Java:Json与其他Java对象集合的转换
  7. J - Invitation Cards
  8. 1001 A + B Problem
  9. IIS的WebGarden、WebFarm和StateServer
  10. 剑指Offer——动态规划算法
  11. 【转录组入门】6:reads计数
  12. Spring Boot 主类及目录结构介绍
  13. [转] 最详尽的 JS 原型与原型链终极详解
  14. what is spring-cloud
  15. 经典的PHPer为什么被认为是草根?
  16. hdu5441 并查集+克鲁斯卡尔算法
  17. 原生WebGL绘制3个点
  18. it喜爱的歌词
  19. U盘去保护方法
  20. JSON.stringify处理对象时的问题

热门文章

  1. Python 获取图片格式及像素宽高信息
  2. REOBJECT structure
  3. python判断文件和文件夹是否存在、创建文件夹
  4. windows盘符操作
  5. 【Java】Java_12 Eclipse
  6. 理解shell中的atime,mtime,ctime
  7. React Native :加载新闻列表
  8. python(30)- 常用模块
  9. velcoity使用说明:foreach指令
  10. 【MyBatis学习06】输入映射和输出映射