熟悉selenium自动化的小伙伴应该知道WebDriver 提供了八种元素定位方法:

id
name
class name
tag name
link text
partial link text
xpath
css selector

appium元素定位和WebDriver略微有些差异,具体差异在哪里,下面会具体介绍,在此之前,我们先打开uiautomatorviewer.bat(在sdk/tools路径下),前置条件,PC连接手机或者模拟器

appium元素定位一:通过 Id 定位

如上图所示resource-id 就是我们要找的 Id 了

使用方法:

driver.findElement(By.id("com.android.calculator2:id/digit_9"))

appium元素定位二:通过Class Name  定位

使用 ClassName 一般获得的 view 都不止一个, 所以应该需要遍历一遍得到的 views, 然后缩小搜索条件来获得目标控件。 不推荐使用

driver.findElement(By.ClassName("android.widget.Button"));

appium元素定位三:通过XPath   定位

找父标签的class

driver.findElement(By.xpath("android.widget.FrameLayout/android.support.v4.view.ViewPager/android.widget.Button"))

appium元素定位四:通过Accessibility ID  定位

这个方法属于 Appium 扩展的定位方法。Accessibility ID 在 Android 上面就等同于 contentDescription。 这个属性是方便一些生理功能有缺陷的
人使用应用程序的。 比如我们有一个 ImageView 里面放置一张颜色复杂的图片, 可能一些色弱色盲的人,分不清这张图片中画的是什么东西。 如果用户安装了辅助浏览工具比如 TalkBack, TalkBack 就会大声朗
读出用户目前正在浏览的内容。 TextView 控件 TalkBack 可以直接读出里面的内容, 但是 ImageView,TalkBack 就只能去读 contentDescription 的值, 告诉用户这个图片到底是什么。
鉴于这是一个隐藏属性, 而 Android 上用于查找控件的各种属性可能有所缺失或者有重复(比如 id重复, 比如一个 list 下面的所有项可能都是叫做“id/text1”) , 所以最佳的办法就是跟开发团队沟通好每个
view 都赋予一个唯一的 contentDescription。其实, 我们的核心是要找到元素的 contentDescription 属性。 它就是元素的 content-desc 。

driver.findElementByAccessibilityId("加").click();

appium元素定位五:通过android uiautomator   定位

AndroidUIAutomator是一个强有力的元素定位方式,它是通过Android UIAutomator类库去找元素,一个元素的任意属性都可以通过 android uiautomator 方法来进行定位, 但要保证这种定位方式的唯一性。

driver.findElementByAndroidUIAutomator("new UiSelector().text(\"+\")").click(); 

4、通过uiautomatorviewer实现appium元素定位的更多相关文章

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

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

  2. appium元素定位总结

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

  3. appium元素定位工具

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

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

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

  5. Appium元素定位(uiautomatorviewer)

    一.uiautomatorviewer元素定位 1.adroid-sdk的安装目录tools下有1个自带的工具uiautomatorviewer,打开后,如下所示: 点击后,如图所示: 步骤: a.链 ...

  6. appium 元素定位工具

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

  7. Appium——元素定位

    首先介绍两种定位元素的工具,appium自带的 Inspector 和 android SDK自带的 uiautomatorviewer 1.UIAutomator Viewer比较简单,在模拟器打开 ...

  8. Python+Appium自动化测试(5)-appium元素定位常用方法

    对于Android而言,查找appUI界面元素属性的工具有三种:appium desktop,uiautomatorviewer.bat,weditor.之前已经介绍过了weditor的使用,这里我将 ...

  9. 『与善仁』Appium基础 — 20、Appium元素定位

    目录 1.by_id定位 2.by_name定位 3.by_class_name定位 4.by_xpath定位 5.by_accessibility_id定位 6.by_android_uiautom ...

随机推荐

  1. border-color:transparent;

    http://www.zhangxinxu.com/study/201111/triangle-css-border.html

  2. Device Drivers

    Types of Device Drivers Windows可能会有User-mode的驱动,但是我们只关注Kernel-Mode的驱动. WDM Drivers WDM是一种驱动模型,是比较常用的 ...

  3. 搭建RAID10(5块硬盘)过程并模拟其中一块硬盘损坏

    首先:RAID 10,实际是将RAID 0和RAID 1标准结合的产物,在连续地以位或字节为单位分割数据并且并行读/写多个磁盘的同时,为每一块磁盘作磁盘镜像进行冗余.它的优点是同时拥有RAID 0的超 ...

  4. leetcode python两整数之和

    # Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ​​​​​​​,计算两整数 `​​​​​​​a `.`b` ​​​​​​​之和. **示例1: ...

  5. 跨域Ajax请求时是否带Cookie的设置

    1. 无关Cookie跨域Ajax请求 客户端 以 Jquery 的 ajax 为例: $.ajax({ url : 'http://remote.domain.com/corsrequest', d ...

  6. C语言指向指针的指针

    #include <stdio.h> int main() { /********************************************* * 指向指针的指针:指针变量存 ...

  7. JSP界面引用百度地图获取坐标

    需求: 需要在JSP界面上引用百度地图,文本框中输入地址之后,自动拿到在百度地图上的经纬度 解决步骤: 1.引入百度地图api: head中进行引用<script type="text ...

  8. Ubuntu16.04+cuda9.0安装教程

    1.安装NVIDIA驱动 首先去官网(http://www.nvidia.cn/Download/index.aspx?lang=cn)查找适配自己电脑GPU的驱动,我的电脑驱动版本如下: 执行如下语 ...

  9. Java删除过期文件

    public static void main(String[] args) throws IOException { long cut = LocalDateTime.now().minusWeek ...

  10. 【转载】RabbitMQ正确的安装方式(windows10)

    链接地址:https://www.cnblogs.com/saryli/p/9729591.html