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. jenkins安装笔记(一)

    转载地址:https://www.cnblogs.com/sylvia-liu/p/4485311.html 自动化架构搭建过程中为实现当开发源码更新时自动化脚本同步触发自动执行,使用到持续集成工具J ...

  2. PHP:第四章——PHP数组添加,删除,插入,分割,合并,及运算符

    <pre> <?php header("Content-Type:text/html;charset=utf-8"); /*知识点一:赋值运算符 = 代码示例:数 ...

  3. Cetus

    转自:https://github.com/Lede-Inc/cetus Cetus 简介 Cetus是由C语言开发的关系型数据库MySQL的中间件,主要提供了一个全面的数据库访问代理功能.Cetus ...

  4. Flask初级(四)flash在模板中使用静态文件

    Project name :Flask_Plan templates: 默认设置下,Flask在程序根目录中名为static的子目录中寻找静态文件. 随便找个图片放进去把,命令test.png Fla ...

  5. C++面向对象多线程入门

    第1节   背景 为了更好的理解多线程的概念,先对进程,线程的概念背景做一下简单介绍. 早期的计算机系统都只允许一个程序独占系统资源,一次只能执行一个程序.在大型机年代,计算能力是一种宝贵资源.对于资 ...

  6. L1-005 考试座位号

    每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考 ...

  7. L224 词汇题

    Elaborate 精心的 preparations were being made for the Prime Minister’s official visit to the four forei ...

  8. vue-cli 添加less 以及sass

    1.sasscnpm i node-sass --save-dev cnpm i sass-loader --save-dev2.less npm install less --save-dev np ...

  9. promise的生命周期

    每个promise都会经历一个短暂的生命周期: 先是处于进行中(pending)状态,此时操作并未完成,所以他也是未处理的(unsettled): 一旦异步惭怍执行结束,promise则 变为已处理( ...

  10. ReactNative——UI2.组件生命周期

    对于习惯了iOS开发的同学,可能会对React Native中组件的生命周期很困惑.在iOS中有一个ViewDidLoad来初始化,那么在RN中,又是在哪里呢? 一.看图分析 在下图中描述了React ...