Appium之uiautomator定位元素
元素定位方式有多种,Android也有自身独有的定位方式。下面就单独介绍其基于uiautomator定位元素的方法:
基本语法:
driver.find_element_by_android_uiautomator(xx)
1).通过text文本定位语法
new UiSelector().text("text文本")
#text
loc_text = 'new UiSelector().text("图书")'
driver.find_element_by_android_uiautomator(loc_text).click()
2).如果文本比较长,可以用textContains模糊匹配
new UiSelector().textContains("包含text文本")
# textContains
loc_textContains = 'new UiSelector().textContains("图")'
driver.find_element_by_android_uiautomator(loc_textContains).click()
3).同样可以用textStartsWith是以某个文本开头来匹配
new UiSelector().textStartsWith("以text文本开头")
#textStartsWith
loc_textStart = 'new UiSelector().textStartsWith("图")'
driver.find_element_by_android_uiautomator(loc_textStart).click()
4).也可以用正则表达式textMatches匹配
new UiSelector().textMatches("正则表达式")
2.resourceId
与by_id一样
new UiSelector().resourceId("id")

#resourceId
loc_id = 'new UiSelector().resourceId("com.baidu.yuedu:id/webbooktitle")'
driver.find_element_by_android_uiautomator(loc_id).click()
3.className
页面上的class属性一般不唯一,多半用在复数定位时候。此时定位相应下标
new UiSelector().className("className")

#className复数定位
loc_class = 'new UiSelector().className("android.widget.TextView")'
driver.find_elements_by_android_uiautomator(loc_class)[2].click()
4.description
也是用contenet-des属性定位
new UiSelector().description("contenet-des属性")
5.组合定位
1).id与text属性组合
#id+text
id_text = 'resourceId("com.baidu.yuedu:id/webbooktitle").text("小说")'
driver.find_element_by_android_uiautomator(id_text).click()
2).class与text属性组合
#class+text
class_text = 'className("android.widget.TextView").text("图书")'
driver.find_element_by_android_uiautomator(class_text).click()
6.关系定位
1).父子定位childSelector
有时候不能直接定位某个元素,但是它的父元素很好定位,这时候就先定位父元素,通过父元素找儿子

如上定位书架:
#父子关系childSelector
son = 'resourceId("com.baidu.yuedu:id/rl_tabs").childSelector(text("小说"))'
driver.find_element_by_android_uiautomator(son).click()
2).兄弟定位fromParent
有时候父元素不好定位,但是跟他相邻的兄弟元素很好定位,这时候就可以通过兄弟元素,找到同一父级元素下的子元素

如上定位书架:
#兄弟关系fromParent
brother = 'resourceId("com.baidu.yuedu:id/lefttitle").fromParent(text("图书"))'
driver.find_element_by_android_uiautomator(brother).click()
Appium之uiautomator定位元素的更多相关文章
- appium 使用findElementByAndroidUIAutomator 定位元素示例
appium 使用findElementByAndroidUIAutomator 定位元素示例 import io.appium.java_client.remote.MobileCapability ...
- Appium+Python3+iOS定位元素
前言: 最近在做IOS自动化测试,IOS的Appium环境都配置OK,执行起来真的慢,慢到怀疑人生,那么今天就来总结一下IOS定位方式和各个定位方式的速度排序. 据我观察,按查找元素的顺序速度,从快到 ...
- 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 ...
- 【appium】根据UIAutomator定位元素
text属性的方法 driver.find_element_by_android_uiautomator('new UiSelector().text("Custom View") ...
- 【appium】根据UIAutomator定位元素等等资料
https://www.cnblogs.com/paulwinflo/p/4742529.html http://www.cnblogs.com/meitian/p/6103391.html http ...
- Appium之xpath定位元素
原文:http://www.cnblogs.com/cnkemi/p/9180525.html appium也是以webdriver为基的,对于元素的定位也基本一致,只是增加一些更适合移动平台的独特方 ...
- uiautomator定位元素
- Python+Appium自动化测试(9)-自动选择USB用于传输文件(不依赖appium对手机页面元素进行定位)
一,问题 app自动化测试使用Android真机连接电脑时,通常会遇到两种情况: 1.测试机连接电脑会弹窗提示USB选项,选择USB用于"传输文件",有些手机不支持设置默认USB选 ...
- Appium脚本(4) 使用uiautomator方法定位元素
from app.find_element.capability import driver from time import sleep # 使用uiautomator方法定位元素 accunt_i ...
随机推荐
- debian7配置iptables
vim /etc/iptables.rule 文件内容如下 *filter # Allows all loopback (lo0) traffic and drop all traffic to / ...
- java之Jsch实现Linux的文件上传与下载
一.JSch是Java Secure Channel的缩写.JSch是一个SSH2的纯Java实现.它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功 ...
- 通过BeanFactoryPostProcessor来获取bean
一.现在我们很多时候都在spring的容器中,进行bean的提取和操作,但是配置里面首先需要扫描相应的包来实现相关bean的注入 但是问题来了.如果我们在另外一个线程需要用的时候,并且没有配置扫描该类 ...
- 转帖:关于MongoDB你需要知道的几件事
Henrique Lobo Weissmann 是一位来自于巴西的软件开发者,他是 itexto 公司的联合创始人,这是一家咨询公司.近日,Henrique 在博客上撰文谈到了关于 MongoDB 的 ...
- 关于rand 与 randn
rand:0-1均匀分布.均值m=(a+b)/2; 方差=(b-a).^2/12; randn:0均值,方差1. 只有当rand和randn生成较大的数据时,均值和方差才会成立.比如N&g ...
- Windows10 IME占用过高临时解决办法
解决方案: 在管理员模式下运行命令提示符,并输入如下命令 if exist "%SystemRoot%\System32\InputMethod\CHS\ChsIME.exe" ( ...
- myeclipse通过数据表生成jpa或hibernate实体
1. 创建数据库连接 2. 选择表 3. 生成 hibernate mapping 4. 生产jpa
- docker 基本使用和安装提速
https://www.cnblogs.com/Erik_Xu/p/6662936.html#redis >yum install -y docker 道客提速 先安装curl >yum ...
- Apache Hadoop 集群安装文档
简介: Apache Hadoop 集群安装文档 软件:jdk-8u111-linux-x64.rpm.hadoop-2.8.0.tar.gz http://www.apache.org/dyn/cl ...
- mybatis使用foreach进行批量插入和删除操作
一.批量插入 1.mapper层 int insertBatchRoleUser(@Param("lists") List<RoleUser> lists);//@Pa ...