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. js通过class获取元素

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta char ...

  2. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  3. bzoj1053&&51nod1060

    题解: 其实就是求1-n之中拥有最多约数的数 一个数x的质因数分解为p1^e1*p2^e2*...*pn^en,则正因数的个数为(e1+1)(e2+1)...(en+1) 那么发现,正因数的个数和p没 ...

  4. [转载]oracle位图索引

    原文URL: http://lzfhope.blog.163.com/blog/static/63639922013119112011947/ 很详细,推荐看5遍

  5. mysql5.7高可用架构之MHA

    一.MHA简介 MHA(Master High Availability)目前在mysql高可用方面比较成熟.是一套优秀的作为 mysql高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障 ...

  6. anu - controlledComponent

    /** input, select, textarea这几个元素如果指定了value/checked的**状态属性**,就会包装成受控组件或非受控组件 受控组件是指,用户除了为它指定**状态属性**, ...

  7. CSS3之border-image

    先上效果图,类似于IPHONE手机左上角的返回按钮样式,如果是在CSS2那么就要做一张背景图片扩展就没那么灵活了,CSS3内就不需要了,CSS3样式挺强大方便的. 源图片: 样式: .banner { ...

  8. linux下yum安装jdk1.8(rpm包)和tomcat-8.5

    Java是目前可移植性较高的语言,相当火热,tomcat运行就需要Java语言环境 ========= 完美的分割线 ========= 0.java简介 1)tomcat运行需要对应的Java环境, ...

  9. PNotes – 目前最优秀的桌面便签软件 - imsoft.cnblogs

    Pnotes: 下载链接: http://pan.baidu.com/s/1o6FK4SM 密码: n7il 便携版,包含中文语音包,包含十几种合适的皮肤. 更多信息:小众软件 http://www. ...

  10. Visual Studio Code 使用指南

       安装 VSCode是微软推出的一款轻量编辑器,采取了和VS相同的UI界面,搭配合适的插件可以优化前端开发的体验. HTML Snippets:增强了zen-coding,增加了H5的自动补全,安 ...