text属性的方法

driver.find_element_by_android_uiautomator('new UiSelector().text("Custom View")').click()         #text
driver.find_element_by_android_uiautomator('new UiSelector().textContains("View")').click() #textContains
driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("Custom")').click() #textStartsWith
driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^Custom.*")').click() #textMatches

class属性的方法

driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("Custom View")').click()     #className
driver.find_element_by_android_uiautomator('new UiSelector().classNameMatches(".*TextView$").text("Custom View")').click() #classNameMatches

 伪xpath方法定位

driver.find_element_by_android_uiautomator('new UiSelector().text("Custom View").fromParent(new UiSelector().text("Accessibility Service"))').click()            #通过同级元素定位同级元素
driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.ListView").childSelector(new UiSelector().text("Custom View"))').click() #通过父级元素定位子集元素

 resourceId属性的方法


driver.find_element_by_android_uiautomator('new UiSelector().resourceId("android:id/text1")')    #resourceId
driver.find_element_by_android_uiautomator('new UiSelector().resourceIdMatches(".*id/text1$")') #resourceIdMatches

description属性的方法
driver.find_element_by_android_uiautomator('new UiSelector().description("Custom View")').click()      #description
driver.find_element_by_android_uiautomator('new UiSelector().descriptionStartsWith("Custom")').click() #descriptionStartsWith
driver.find_element_by_android_uiautomator('new UiSelector().descriptionMatches("^Custom.*")').click() #descriptionMatches

 元素的其他属性

除了以上比较常用的方法外,UIAutomator还支持其他一些方法,比如根据控件属性是否可点击可聚焦可长按等来缩小要定位的控件的范围,具体使用方法不一一列举(checked,clickable,focesed.......)

driver.find_element_by_android_uiautomator('new UiSelector().clickable(true).text("Custom View")').click()
 

【appium】根据UIAutomator定位元素的更多相关文章

  1. Appium之uiautomator定位元素

    元素定位方式有多种,Android也有自身独有的定位方式.下面就单独介绍其基于uiautomator定位元素的方法: 基本语法: driver.find_element_by_android_uiau ...

  2. appium 使用findElementByAndroidUIAutomator 定位元素示例

    appium 使用findElementByAndroidUIAutomator 定位元素示例 import io.appium.java_client.remote.MobileCapability ...

  3. Appium+Python3+iOS定位元素

    前言: 最近在做IOS自动化测试,IOS的Appium环境都配置OK,执行起来真的慢,慢到怀疑人生,那么今天就来总结一下IOS定位方式和各个定位方式的速度排序. 据我观察,按查找元素的顺序速度,从快到 ...

  4. Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

    使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be fou ...

  5. 【appium】根据UIAutomator定位元素等等资料

    https://www.cnblogs.com/paulwinflo/p/4742529.html http://www.cnblogs.com/meitian/p/6103391.html http ...

  6. Appium之xpath定位元素

    原文:http://www.cnblogs.com/cnkemi/p/9180525.html appium也是以webdriver为基的,对于元素的定位也基本一致,只是增加一些更适合移动平台的独特方 ...

  7. uiautomator定位元素

  8. Python+Appium自动化测试(9)-自动选择USB用于传输文件(不依赖appium对手机页面元素进行定位)

    一,问题 app自动化测试使用Android真机连接电脑时,通常会遇到两种情况: 1.测试机连接电脑会弹窗提示USB选项,选择USB用于"传输文件",有些手机不支持设置默认USB选 ...

  9. Appium脚本(4) 使用uiautomator方法定位元素

    from app.find_element.capability import driver from time import sleep # 使用uiautomator方法定位元素 accunt_i ...

随机推荐

  1. PHP:第一章——php中数据类型和强制类型转换

    <?php //PHP中的数据类型: //标量类型:布尔型(boolean).整型(integer).浮点型(float).字符串型(string) //复合类型:数组(array).对象(ob ...

  2. Vue 框架中遇到的诀窍

    问题一. 我需要渲染数组A,并根据 B数组中是否存在A中,给A添加 选中状态sel. 经过很焦虑的研究后,寻求帮助得到答案. 1.初始化数据时 A添加属性flag(bool)标识,如果B中存在A中某个 ...

  3. 微信H5支付 C#

    首先奉上 万能的    官方文档 应用场景(废话) H5支付是指商户在微信客户端外的移动端网页展示商品或服务,用户在前述页面确认使用微信支付时,商户发起本服务呼起微信客户端进行支付.         ...

  4. 数据库SQL优化大总结之 百万级数据库优化方案(转载)

    网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉 ...

  5. magento如何在首页显示产品

    1.首先现在magento后台创建一个新的分类,记下这个分类的 ID 号码.使用这个新建的分类来管理你的首页产品,这个分类设置为前台不可见.这样就不会显示在你的分类菜单中了,但使用代码调用的时候却会显 ...

  6. 第十章 企业项目开发--分布式缓存Redis(2)

    注意:本章代码是在上一章的基础上进行添加修改,上一章链接<第九章 企业项目开发--分布式缓存Redis(1)> 上一章说了ShardedJedisPool的创建过程,以及redis五种数据 ...

  7. opencv图像读取-imread

    前言 图像的读取和保存一定要注意imread函数的各个参数及其意义,尽量不要使用默认参数,否则就像数据格式出现错误(here)一样,很难查找错误原因的: re: 1.opencv图像的读取与保存; 完

  8. Springboot中的连接池

    pom.xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-ja ...

  9. No.02——第一次使用Android Studio,并创建出Hello World

    1.第一次打开Studio 2.点击创建新项目 然后填上相关信息,注意在Company Domain(公司域名)地方的填写,不同于Eclipse对应实际电脑中文件夹,而是在你所选择的Project文件 ...

  10. CodeForces - 1093G:Multidimensional Queries (线段树求K维最远点距离)

    题意:给定N个K维的点,Q次操作,或者修改点的坐标:或者问[L,R]这些点中最远的点. 思路:因为最后一定可以表示维+/-(x1-x2)+/-(y1-y2)+/-(z1-z2)..... 所以我们可以 ...