原文地址http://blog.csdn.net/wuyepiaoxue789/article/details/77885136

元素属性的介绍

type:元素类型,与className作用一致,如:XCUIElementTypeStaticText
value: 一般不用
name:元素的文本内容,可用作 AccessibilityId定位方式,如:测试420班级群
label:绝大多数情况下,与 name 作用一致
enabled:元素是否可点击,一般值为true或者false
visible:元素是够可见,一般值为true或者false

1.findElementByIosNsPredicate

这个定位方式需要用java-client -5.0.版本,4.x的版本没有这个定位方式

.findElementByIosNsPredicate

.findElementByIosNsPredicate

.findElementByIosNsPredicate

.findElementByIosNsPredicate

.findElement

仅支持
iOS 10或以上,可支持元素的单个属性和多个属性定位,推荐使用。
一种属性:MobileBy.iOSNsPredicateString("type
== 'XCUIElementTypeButton'")

两种属性:MobileBy.iOSNsPredicateString("type
== 'XCUIElementTypeButton' AND label == '更多信息'")

具体 iOSNsPredicate语法结构可查看官方文档,或查看的这个帖子:iOS
定位方式 iOSNsPredicateString 详解

Appium 的定位方式种类

我说的定位方式都是基于我自己亲测过,没使用或比较少用的就在这里不列举了,如有错误的地方,请多多包涵!常用的定位方式(仅限 Android 和 iOS 两种系统)有 className、id、xpath、AccessibilityId、AndroidUIAutomator、iOSNsPredicateString、iOSClassChain、IosUIAutomation等

className

使用元素的className属性定位,支持:Android 和 iOS,推荐使用。
MobileBy.className("XCUIElementTypeButton")

id

使用元素的Resource Id属性定位,支持:Android,仅支持 Android 4.3或以上,推荐使用。反正我没有在 iOS 用过,大家有正确使用过的例子,可以分享一下。
MobileBy.id("package.name:id/android")

xpath

支持:Android 和 iOS。但由于 iOS 10开始使用的 XCUITest 框架原声不支持,定位速度很慢,所以官方现在不推荐大家使用,也有其他替代的定位方式可使用。
1.使用绝对路径定位,如截图所显示的 xpath 路径
MobileBy.xpath("className/className/className/className")
2.使用相对路径定位
MobileBy.xpath("//className")
3.通过元素的索引定位
MobileBy.xpath("//className[index]")
4.通过元素的属性定位
一种属性:MobileBy.xpath("//className[@label='更多信息']")
两种属性:MobileBy.xpath("//className[@label='更多信息'][@isVisible='1']")
部分属性(最强大):MobileBy.xpath("//className[contains(@label,'更多')]")

AccessibilityId

替代以前的name定位方式,推荐使用。
在 Android 上,主要使用元素的content-desc属性,如该属性为空,不能使用此定位方式。
在 iOS 上,主要使用元素的labelname(两个属性的值都一样)属性进行定位,如该属性为空,如该属性为空,也是不能使用该属性。
MobileBy.AccessibilityId("更多信息")

AndroidUIAutomator

仅支持 Android 4.2或以上,可支持元素的单个属性和多个属性定位,推荐使用。
一种属性:MobileBy.AndroidUIAutomator("new UiSelector().text(\"发送\")")
两种属性:MobileBy.AndroidUIAutomator("new UiSelector().text(\"发送\").clickable(true)")
元素的所有属性都可用做定位,功能非常强大,且速度很快。

iOSNsPredicateString

仅支持 iOS 10或以上,可支持元素的单个属性和多个属性定位,推荐使用。
一种属性:MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton'")
两种属性:MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND label == '更多信息'")
具体 iOSNsPredicate语法结构可查看官方文档,或查看的这个帖子:iOS 定位方式 iOSNsPredicateString 详解

iOSClassChain

仅支持 iOS 10或以上,这是 github 的 Mykola Mokhnach 大神开发,仅限在 WebDriverAgent 框架使用,用于替代 xpath 的,但使用一阵子后,感觉灵活性没有 xpath 和 iOSNsPredicate 好,应该还不完善吧。具体使用方法,请见:https://github.com/appium/appium-xcuitest-driver/pull/391 。
MobileBy.iOSClassChain('XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeNavigationBar[1]/XCUIElementTypeOther[1]/XCUIElementTypeButton[2]')

IosUIAutomation

仅支持 iOS 9.3或以下,是 iOS 旧框架 UIAutomation 的定位方式,现在基本上很少使用,这个定位类型同样可使用 iOS 谓词进行定位,详细可参考:iOSNsPredicate

总结:
以上这个多定位方式,很少说全部用完。根据我的经验,推荐使用:Android:AndroidUIAutomator > className = id = AccessibilityId > xpath。iOS:iOSNsPredicateString > className = AccessibilityId

IOS自动化定位方式的更多相关文章

  1. selenium自动化定位方式

    自动化定位方式 1.String Xpath = String.format("//*[@id=\"saveFileKeyWordsBtnHand\"]/../../.. ...

  2. android和IOS自动化定位方法

    元素定位 方法:id定位,name定位(text定位),class_name定位, accessibility_id定位,xpath定位等 (目前1.5版本的已经不支持name定位了),所以APP的定 ...

  3. iOS 定位方式 iOSNsPredicateString 详解

    原文地址https://segmentfault.com/a/1190000010205649 前言 由于使用id.className.AccessibilityId定位方式较为简单,多数情况下,在同 ...

  4. Appium iOS万能的定位方式--Predicate(iOSNsPredicate)

    所谓Predicate定位即Java-Client -5.0.版本以及Appium-Python-Client 0.31版本更新后增加的新的定位方式: 举个例子: JAVA代码: //输入账号和密码 ...

  5. App自动化之dom结构和元素定位方式(包含滑动列表定位)

    900×383 38 KB 先来看几个名词和解释: dom: Document Object Model 文档对象模型 dom应用: 最早应用于html和js的交互.界面的结构化描述, 常见的格式为h ...

  6. 移动端自动化==>Appium定位方式总结

    1.ID Android Android的resource-id对应ID定位方式,可以通过index来获取需要的元素(从0开始查找dom树中的同名resource-id属性).使用appium-des ...

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

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

  8. App自动化《元素定位方式、元素操作、混合应用、分层设计、代码方式执行Pytest 命令》

    坚持原创输出,点击蓝字关注我吧 作者:清菡 博客:oschina.云+社区.知乎等各大平台都有. 目录 一.App 元素定位方式 二.元素操作 三.测试混合应用 四.以代码的方式执行 Pytest 命 ...

  9. APPIUM-Android自动化元素定位方式

    一.常用元素定位方法 appium从selenium中继承了所有的元素定位方法, 并且增加了一些自己的元素定位方式,下方截图分别为selenium和MobileBy包源码: 但是从继承selenium ...

随机推荐

  1. Android不同版本下Notification创建方法

    项目环境 Project Build Target:Android 6.0 问题: 使用 new Notification(int icon, CharSequence tickerText, lon ...

  2. 学习:erlang读取文件中的terms

    参考:http://diaocow.iteye.com/blog/1766128 1. file:consult(Filename) -> {ok, Terms} | {error, Reaso ...

  3. c#用run32dll打开系统dll(如系统图片查看器,并置最顶层)

    [DllImport("user32.dll", EntryPoint = "SetWindowPos",CharSet = CharSet.Auto)] st ...

  4. jQuery实用技巧必备

    本文实例总结了经典且实用的jQuery代码开发技巧.分享给大家供大家参考.具体如下: 1. 禁止右键点击 $(document).ready(function(){  $(document).bind ...

  5. 《Programming with Objective-C》第五章 Customizing Existing Classes

    1.分类里面只新增函数,不要新增变量:虽然新增是语法合法的,但是编译器并不会为你的property合成相应的成员变量.setter和getter Categories can be used to d ...

  6. hdu 4496(并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496. 思路:简单并查集应用,从后往前算就可以了. #include<iostream> ...

  7. Java Web项目--使用Servlet生成一个页面

    为了生成一个servlet对应的网页.我们需要新建一个web.xml,其中将会放置servlet的相关信息.web.xml文件放置在WebContent/WEB-INF/目录下.(我们在Eclipe中 ...

  8. JSP内置对象——out,get与post

    JSP内置对象是Web容器创建的一组对象,不使用new关键字就可以的内置对象.JSP九大内置对象:out,request,response,session,application,page,pageC ...

  9. 三、Gradle初级教程——Gradle除了签名打包还能配置jar包

    1.gradle概念 构建工具,Groovy,Java. 2.gradle配置jar包,和libs文件夹导入jar包的区别 到此,还是这种方法导入JAR包比较方便.每次更新JAR包,只需要修改版本号就 ...

  10. 75、JSON 解析库---FastJson, Gson

    JSON 的简介: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.用于数据转换传输, 通用于PHP,Java,C++,C#,Python等编程语言数据交 ...