说在前面

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 -------------元素定位的更多相关文章

  1. 初探appium之元素定位(1)

    无论是selenium还是appium,元素定位都是我们开始实现自动化面临的第一个问题.selenium还好,我们可以在浏览器的调试页面进行元素定位还是蛮方便的.那么appium怎么做呢? 我看到很多 ...

  2. Appium Android 元素定位方法 原生+H5

    APPIUM Android 定位方式   1.定位元素应用元素 1.1通过id定位元素 Android里面定位的id一般为resrouce-id: 代码可以这样写: WebElement eleme ...

  3. Appium Desktop 元素定位和脚本录制功能

    Appium Desktop除了可以做Server之外还可以进行元素定位和脚本录制功能,点击放大镜按钮,进入页面设置.开始配置Desired Capabilities. 配置Desired Capab ...

  4. Appium自动化(10) - appium高级元素定位方式之 UI Automator API 的详解

    如果你还想从头学起Appium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1693896.html 前言 前面介绍过根据id,clas ...

  5. selenium webdriver python 元素定位

    总结   定位查找时,返回查找到的第一个match的元素.如果找不到,则 raise NoSuchElementException   单个元素定位: find_element_by_idfind_e ...

  6. Appium+Python 自动化-appium常用元素定位方法

    https://www.cnblogs.com/rabbit-testing/p/8042733.html 大牛 https://blog.csdn.net/kaka1121/article/deta ...

  7. appium xpath元素定位

    1.id定位 写法:driver.find_element_by_id("这里是resource-id") 2.name定位 name定位就是通过UI Automator工具查看的 ...

  8. Appium + python - long_press定位操作实例

    from appium.webdriver.common.touch_action import TouchActionfrom appium import webdriverimport timei ...

  9. Appium + python - automator定位操作

    # coding:utf-8from appium import webdriverfrom time import sleep desired_caps = { 'platformName': 'A ...

随机推荐

  1. [Hibernate] - Query Select

    测试了常用的一些HQL查询方法,具体HQL的强大可以参考: http://docs.jboss.org/hibernate/orm/3.5/reference/zh-CN/html/queryhql. ...

  2. [Hibernate] - Annotations - One To Many

    Hibernate使用Annotation的一对多: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8&q ...

  3. 【linux】/etc/passwd文件

    /etc/passwd文件内容格式 /etc/passwd是保存用户信息的文件. 格式:用户名: 密码 : uid  : gid :用户描述:主目录:登陆shell 举个例子: root:x:0:0: ...

  4. 【oracle】数据库、表空间、用户、数据表之间的关系

    来自为知笔记(Wiz) 附件列表 新建_032515_030437_PM.jpg

  5. Office导入导出组件权限配置汇总

    NET导出Excel遇到的80070005错误的解决方法: 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现 ...

  6. java学习笔记(二)之数据部分

    数据类型 java数据类型 基本数据类型 数值型 整型byte/short/int/long   浮点型/double/float   字符型char     布尔型boolean 取值true  f ...

  7. 【SQL Server】系统学习之三:逻辑查询处理阶段-六段式

    一.From阶段 针对连接说明: 1.笛卡尔积 2.on筛选器 插播:unknown=not unknuwn 缺失的值: 筛选器(on where having)把unknown当做FALSE处理,排 ...

  8. 转--简单工厂模式 Simple Factory

    简单工厂模式的作用就是定义一个用于创建对象的接口 在简单工厂模式中,一个工厂类处于对产品类实例化调用的中心位置上,它决定那一个产品类应当被实例化.         先来看看它的组成: 1) 工厂类角色 ...

  9. Java 内存泄露

    一.Java内存回收机制 不论哪种语言的内存分配方式,都需要返回所分配内存的真实地址,也就是返回一个指针到内存块的首地址.Java中对象是采用new或者反射的方法创建的,这些对象的创建都是在堆(Hea ...

  10. ylbtech-Unitity-CS-Arrays:数组

    ylbtech-Unitity-CS-Arrays:数组 1.A,效果图返回顶部   1.B,源代码返回顶部 1.B.1, using System; class DeclareArraysSampl ...