Appium + Python -------------元素定位
说在前面
1、https://github.com/appium/python-client/tree/master/test 里面有一些test ,可以看看,研究研究
2、学会使用 uiautomatorviewer 和 hierarchyviewer ,这两个工具可以帮助查看app一些信息,非常好用,在android-tools下
控件的特征就是控件的属性,所以我们可以根据控件的特征进行定位
PS:断言部分之后再细说
1、find_elements_by_accessibility_id,以accessibility_id进行定位,对Android而言,就是content-description属性(使用uiautomatorviewer 可以查看到) ,所以参数不要弄错
el = self.driver.find_element_by_accessibility_id(u'请输入QQ号码或手机或邮箱') #以QQ登录页为例
self.assertIsNotNone(el) els = self.driver.find_elements_by_accessibility_id('请输入QQ号码或手机或邮箱')
self.assertIsInstance(els, list)
2、find_element_by_class_name,根据class进行定位
self.driver.find_element_by_class_name("android.widget.EditText") # 定位唯一元素
self.driver.find_elements_by_class_name("android.widget.EditText")[0] # 找到所有android.widget.EditText并定位第一个
3、find_elemnt_by_name ,根据name进行定位,对于android来说,就是text属性
e3 = self.driver.find_element_by_name(u"登 录")
4、find_element_by_android_uiautomator ,使用uiautomator定位,后面参数更改即可
UiSelector().text 根据text属性进行定位
self.driver.find_element_by_android_uiautomator('new UiSelector().text("33001122")')UISelector.textContains 根据text属性模糊定位
e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("1122")')UISelector.textStartsWith 根据text的前面几位是否与text一致来定位
e7 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("33")')UISelector.textMatches 通过正则表达式和text来进行定位,正则不怎么会,先不扩展了
UISelector.className 通过class来进行定位,合理利用层级定位,例如找到所有的Edittext然后根据text定位
e8 = self.driver.find_element_by_android_uiautomator('new UiSelector()'
'.className("android.widget.EditText")'
'.textContains("33")')UISelector.classNameMatches 通过正则表达式和class来进行定位
还有UiSelector.descriptionMatches 、 UiSelector.descriptionStartWith 、UiSelector.description
5、driver.find_element_by_id 与 UiSeletor.resourceId 都是通过resourceId 来进行定位,这个属性只有在Api Level18以上才有
e9 = self.driver.find_element_by_android_uiautomator('new Uiseletor()'
'.resourceId'
'("com.taobao.qianniu:id/accountCompleteTextView")')
e10 = self.driver.find_element_by_id("com.taobao.qianniu:id/accountCompleteTextView")
--------如果上面说的有什么问题,麻烦大家及时扣扣我!感恩!
--------会不定时更新,转载请说明原文
Appium + Python -------------元素定位的更多相关文章
- 初探appium之元素定位(1)
无论是selenium还是appium,元素定位都是我们开始实现自动化面临的第一个问题.selenium还好,我们可以在浏览器的调试页面进行元素定位还是蛮方便的.那么appium怎么做呢? 我看到很多 ...
- Appium Android 元素定位方法 原生+H5
APPIUM Android 定位方式 1.定位元素应用元素 1.1通过id定位元素 Android里面定位的id一般为resrouce-id: 代码可以这样写: WebElement eleme ...
- Appium Desktop 元素定位和脚本录制功能
Appium Desktop除了可以做Server之外还可以进行元素定位和脚本录制功能,点击放大镜按钮,进入页面设置.开始配置Desired Capabilities. 配置Desired Capab ...
- Appium自动化(10) - appium高级元素定位方式之 UI Automator API 的详解
如果你还想从头学起Appium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1693896.html 前言 前面介绍过根据id,clas ...
- selenium webdriver python 元素定位
总结 定位查找时,返回查找到的第一个match的元素.如果找不到,则 raise NoSuchElementException 单个元素定位: find_element_by_idfind_e ...
- Appium+Python 自动化-appium常用元素定位方法
https://www.cnblogs.com/rabbit-testing/p/8042733.html 大牛 https://blog.csdn.net/kaka1121/article/deta ...
- appium xpath元素定位
1.id定位 写法:driver.find_element_by_id("这里是resource-id") 2.name定位 name定位就是通过UI Automator工具查看的 ...
- Appium + python - long_press定位操作实例
from appium.webdriver.common.touch_action import TouchActionfrom appium import webdriverimport timei ...
- Appium + python - automator定位操作
# coding:utf-8from appium import webdriverfrom time import sleep desired_caps = { 'platformName': 'A ...
随机推荐
- Java 读Properties
import java.io.*; import java.util.Properties; public class Study { public static void main(String[] ...
- 【python】sys.argv[]的用法
在学python的过程中,一直弄不明白sys.argv[]的意思,虽知道是表示命令行参数,但还是有些稀里糊涂的感觉. 今天又好好学习了一把,总算是大彻大悟了. Sys.argv[]是用来获取命令行参数 ...
- js禁止从浏览器缓存读取消息
$.ajaxSetup ({ cache: false //设置成false将不会从浏览器缓存读取信息 });
- 【原】Centos 7 下创建LVM流程
阅读目录 个主分区,1个扩展分区] 或 [4个主分区],扩展分区又可以有多个分区: window常见的分配方式: 方式1:[1个主分区(C盘)+1个扩展分区(包括3个分区,D,E, ...
- C#调用MySql
1.要连接MySql数据库必须首先下载MySql官方的连接.net的文件,文件下载地址为http://dev.mysql.com/downloads/connector/net/6.6.html#do ...
- 修改mongodb oplog size
转载地址:http://blog.csdn.net/huwei2003/article/details/43307647 修改mongodb oplog size oplog简介: oplog:ope ...
- php没有开启Memcache扩展类时
模拟PHP Memcache 类.当服务器没有开启Memcache扩展的时候.可以采用本类使用方法class_exists('Memcache') or include './Memcache.cla ...
- Android优秀资源整理合集(论菜鸟到高级攻城狮)
转载请注明转自:http://blog.csdn.net/u011176685/article/details/51434702 csdn文章:Android优秀资源整理合集(论菜鸟到高级攻城狮) 时 ...
- Qt中在图片上叠加显示文字
Qt中在图片上叠加显示文字 QCustLabel::QCustLabel(QWidget *parent):QLabel(parent){ setPixmap(QPixmap(QString::f ...
- Ubuntu编写开机自启动脚本(转载)
From:http://blog.csdn.net/marujunyy/article/details/8466255 1.首先编写一个简单的shell脚本test.sh #! /bin/bash e ...