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. eclipse设置条件断点

    1. 在Breakpoints页面,选中断点然后右键,选择"Breakpoint Properties" 2. 勾选Conditional,并输入条件.这样,当name等于&quo ...

  2. 修改MAC地址的方法(未测试)

    用ioctl控制,通过SIOCGIFHWADDR获取MAC地址,SIOCSIFHWADDR设置MAC地址,不过在设 置MAC地址之前,要先把网卡down掉,设置好了以后,再UP起来. #include ...

  3. dup的使用(二)

    转自:http://blog.csdn.net/yeyuangen/article/details/6852682 一个进程在此存在期间,会有一些文件被打开,从而会返回一些文件描述符,从shell中运 ...

  4. hibernate--一级和二级缓存(使用Ehcache)以及查询缓存

    https://blog.csdn.net/u012411414/article/details/50483185 有一下几点需要理清才行: 一级缓存是session缓存 session关闭就小时 二 ...

  5. SQL Server 调优系列基础篇 - 并行运算总结(二)

    前言 上一篇文章我们介绍了查看查询计划的并行运行方式. 本篇我们接着分析SQL Server的并行运算. 闲言少叙,直接进入本篇的正题. 技术准备 同前几篇一样,基于SQL Server2008R2版 ...

  6. 返回最小的k个数

    对于一个无序数组,数组中元素为互不相同的整数,请返回其中最小的k个数,顺序与原数组中元素顺序一致. 给定一个整数数组A及它的大小n,同时给定k,请返回其中最小的k个数. 测试样例: [1,2,4,3] ...

  7. W1002 Symbol 'Create' is specific to a platform

    http://stackoverflow.com/questions/9099892/how-to-use-tformatsettings-create-without-being-specific- ...

  8. SharePoint场管理-PowerShell(一)

    1. 查看场配置信息 Get-SPFarmConfig 2. 设置场配置信息 Set-SPFarmConfig –ASPScriptOptimizationEnabled:$true –DataFor ...

  9. Python入门——第一个Python程序

    1.1 Hello Python书写步骤 步骤一:新建文本文档文件,修改名称为hello.py 步骤二:使用记事本打开文件,书写程序内容如下: print("hello python&quo ...

  10. Linux下常用的ftp操作命令

    Linux下常用的ftp操作命令 =========== 完美的分割线 ============= 1.登陆ftp服务器 ftp [IP] [PORT] # 登陆ftp服务器,本机登陆可以不写IP 实 ...