UIAutomator 元素定位是 Android 系统原生支持的定位方式,虽然与 xpath 类似,但比它更好用,并且支持元素全部的属性定位,定位原理是通过 android 自带的android uiautomator 的类库去查找元素

  方法名:find_element_by_android_uiautomator('uiSelector 表达式')

  该方法的参数为 UiSelector 类定位元素的表达式:new UiSelector().函数名称("定位表达式")

  实例化一个 UiSelector 对象,然后通过实例调用对应的方法,每一个方法返回的都是UiSelector 对象本身

  注意:UiSelector 类下面的函数的参数如果是字符串,必须是双引号,这是 Java 的语法风格,在 Java 中,双引号才表示字符串

UiSelector 类的函数如下:

1.资源id方法

  • resourceId(String id)  资源 id
  • resourceIdMatches(String regex)  资源 id 正则

2.文本方法

  • text(String text)  文本匹配
  • textContains(String text)  文本包含
  • textStartsWith(String text)  文本开始字符
  • textMatches(String regex)  文本正则

3.描述方法

  • description(String desc)  描述
  • descriptionContains(String desc)  描述包含
  • descriptionStartsWith(String desc)  描述开始字符
  • descriptionMatches(String regex)  描述正则

4.类名方法

  • childSelector(UiSelector selector)  子类
  • fromParent(UiSelector selector)  父类
  • className(String className)  类名

5.索引、实例方法

  • index(int index)  编号
  • instance(int instance)  索引

6.特有属性方法

  • checked(boolean val)  选择属性
  • checkable(boolean val)  点击属性
  • enabled(boolean val)  enabled 属性
  • focusable(boolean val)  焦点属性
  • longClickable(boolean val)  长按属性
  • scrollable(boolean val)  滚动属性
  • selected(boolean val)  选择属性

7.包名方法

  • packageName(String name)  包名
  • packageNameMatches(String regex)  包名正则

示例:

new UiSelector().text("text")  # 使用元素 text 属性定位
new UiSelector().resourceId("id") # 使用 id 定位
new UiSelector().className("className") # 使用元素类型定位 # 还可以元素多个属性自由组合
new UiSelector().className("className").text("text")
new UiSelector()..resourceId("id").clickable(val)

appium元素定位之AndroidUiAutomator的更多相关文章

  1. 4、通过uiautomatorviewer实现appium元素定位

    熟悉selenium自动化的小伙伴应该知道WebDriver 提供了八种元素定位方法: idnameclass nametag namelink textpartial link textxpathc ...

  2. Python Appium 元素定位方法简单介绍

    Python  Appium  元素定位 常用的八种定位方法(与selenium通用) # id定位 driver.find_element_by_id() # name定位 driver.find_ ...

  3. appium元素定位总结

    appium元素定位方法总结 使用uiautomator定位 driver.find_element_by_android_uiautomator(uia_string) 根据resourceId属性 ...

  4. appium元素定位工具

      appium元素定位工具介绍 使用uiautomatorviewer定位工具 使用Appium Inspector定位工具 使用uiautomatorviewer定位工具 谷歌在Android S ...

  5. APP 自动化之appium元素定位(三)

    APP自动化测试关键环节--元素定位,以下我们来了解appium提供的元素定位方法! 1. id定位,id一个控件的唯一标识,由开发人员在项目中指定,如果一个元素有对应的resource-id,我们就 ...

  6. appium 元素定位方法汇总

    以上图为例,要定位到右下角的 我的 ,并点击 # appium的webdriver提供了11种元素定位方法,在selenium的基础上扩展了三个,可以在pycharm里面输入driver.find_e ...

  7. appium 元素定位工具

    两种元素定位工具: 1.uiautomatorviewer是android-sdk自带的一个元素定位工具,目录D:\androidsdk\androidsdk\tools\bin . 双击启动uiau ...

  8. appium 元素定位与操作:

    一.常用识别元素的工具   uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录下 Appium I ...

  9. appium===元素定位

    一.常用识别元素的工具 uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录下 Appium Ins ...

随机推荐

  1. 002_Java语言基础

    ------------恢复内容开始------------ 存储的基本单元:byte: 1 byte = 8 bit(位) 1 KB = 1024 byte 1 MB = 1024 KB 1 GB ...

  2. Electron开发和Web开发对比

  3. java项目测试环境搭建

    java项目测试环境搭建 2019-03-06 13:45:26 木瓜小少年 阅读数 691更多 分类专栏: 测试   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原 ...

  4. Linux防火墙的相关资料

    1.查看防火墙状态 [root@localhost ~]# service iptables status 2.编辑/etc/sysconfig/iptables文件.我们实例中要打开8080端口和9 ...

  5. Flutter - You need to use a different version code for your APK or Android App Bundle because you already have one with version code 1.

    前两天提交了一个版本Google Play,结果今天收到拒绝的邮件,说App内购有问题. 于是把设置里面的支付宝和微信打赏功能关闭,又打了一个aab. 然后上传到Google Play,结果提示 Yo ...

  6. php 弱类型总结

    0x01 前言 最近CTF比赛,不止一次的出了php弱类型的题目,借此想总结一下关于php弱类型以及绕过方式 0x02 知识介绍 php中有两种比较的符号 == 与 === <?php $a = ...

  7. 3.Android-ADT之helloworld项目结构介绍

    1.helloworld项目结构如下图所示: src 放项目的源代码的.而MainActivity.java文件则对应helloworld界面代码,代码如下所示: gen BuildConfig.ja ...

  8. 使用shell脚本删除30天以前的文件

    #!/bin/bashlocation=/root/rmfind $location -mtime +30 -print | xargs rm -rf //-mtime是距离上一次修改时间 -prin ...

  9. c++11多线程笔记

    1 thread类thread f;线程等待join()线程分离detach() thread类不可拷贝复制 std::this_thread::yield(); 2 bind 与lambda表达式 ...

  10. PHP-FPM 使用(含多站点多端口)

    PHP-FPM 使用 PHP-FPM 是在 Linux 环境下用来管理调度 PHP 执行的调度器,源码安装时会自动安装,PHP 安装可参考Centos 下安装 PHP (新) 查看版本 # php-f ...