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 ...
随机推荐
- IOS开发小项目—找色块游戏
1.项目代码: @interface NextViewController () { int r ;//色块层数的全局变量 int m;//后面用于tag值的变化 UIView *view;//色块 ...
- row_number()over(order by id) SQL顺序排列
select *,row_number()over(order by id) as number_id from [dbo].tb_pccw20140213
- Android AVD创建及设置中各参数详解
设置AVD时有些参数比较模糊,特地找了篇文章,大家参考下! 本文根据如下的模拟器安装做一些解释: Name:自定义虚拟的名称,不能有空格或者其他非法字符,否则不能创建,即Creat AVD不能高亮点击 ...
- 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- spring+springMVC+mybatis的框架项目基础环境搭建
上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...
- Linux大文件传输(转)
我们经常需要在机器之间传输文件.比如备份,复制数据等等.这个是很常见,也是很简单的.用scp或者rsync就能很好的完成任务.但是如果文件很大,需要占用一些传输时间的时候,怎样又快又好地完成任务就很重 ...
- [转]将Word转(保存)为带书签的PDF
提到的方法非常管用,感谢原作者的分享. 原文地址:http://blog.163.com/rongting_chen/blog/static/16490684420114266192887/ 将wor ...
- 基于redis的分布式锁
<?php /** * 基于redis的分布式锁 * * 参考开源代码: * http://nleach.com/post/31299575840/redis-mutex-in-php * * ...
- python(8) 自己制造异常让程序退出,把print的内容写入到文件
异常 也可以自己输出异常原因: raise Exception("404 404 404") import math import time #print 到文件的代码****** ...
- android-Service和Thread的区别
1.服务不是单一的进程.服务没有自己的进程,应用程序可以不同,服务运行在相同的进程中. 2.服务不是线程.可以在线程中工作. 一.在应用中,如果是长时间的在后台运行,而且不需要交互的情况下,使用服务. ...