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 ...
随机推荐
- 用JS获取DropDownList选中得值
HTML: <asp:DropDownList ID="DropdownList1" runat="server" AutoPostBack=" ...
- LintCode "Triangle Count"
Should be "Medium" or even "Easy".. Just with a little Greedy. class Solution { ...
- IntelliJ IDEA中怎么查看方法说明?
View→Quick Documentation 查看当前配置的快捷键(例如Ctrl + Q) 在光标所在的方法上按下快捷键就可以看到方法的说明 下图为在View菜单中查看当前配置的快捷键截图: 下图 ...
- erlang和java通信
连接在 https://guts.me/2014/07/27/erlang-communicates-with-java/ 代码在 https://github.com/mingshun/jinter ...
- python学习-day02
---恢复内容开始--- 一.pycharm安装 1.1破解方式http://www.cnblogs.com/evlon/p/4934705.html 1.2.头部配置: 二.运算符 2.1.比较运算 ...
- ASP.NET的POST和GET提交并接收处理返回值
POST方法: 数据提交 /// <summary> /// POST提交数据接收字符json /// </summary> /// <param name=" ...
- UIActivityIndicatorView添加到UIButton上并响应事件
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewSty ...
- 二. Socket用法
C/S通信架构中,客户端要主动与服务端建立连接,这个链接就是Socket套接字.服务端收到连接请求后,也会开启Socket记录与客户端的链接.C/S两端都要建路Socket才能正常收发数据. 一.构造 ...
- java.lang.StackOverflowError: stack size 8MB
java.lang.StackOverflowError: stack size 8MB at android.text.TextUtils.getChars(TextUtils.java:86) a ...
- 两分钟彻底让你明白Android Activity生命周期(图文)!
大家好,今天给大家详解一下Android中Activity的生命周期,我在前面也曾经讲过这方面的内容,但是像网上大多数文章一样,基本都是翻译Android API,过于笼统,相信大家看了,会有一点点的 ...