通过appium-desktop定位元素

ClassName

Android

Android的class属性对应ClassName定位方式,ClassName一般都是会重复的,可以通过index来获取需要的元素。(从0开始查找dom树中的同名class属性)

iOS

iOS的type属性对应CLassName定位方式,ClassName一般都是会重复的,可以通过index来获取需要的元素。(从0开始查找dom树中的同名class属性)

ID

Android

Android的resource-id对应ID定位方式,这个id也可能存在重复情况,可以通过index来获取需要的元素。(从0开始查找dom树中的同名resource-id属性)

使用appium-desktop来获取元素时,如果提示有id的定位方式,则可以只接获取,代表唯一。

XPATH

Android

Android的Xpath定位与PC的XPATH定位大同小异,可以通过相对路径的定位方式定位,区别在于,这里相对路径定位的//后只可以接Android的class属性或*。(//android.widget.Button[@text="登 录"])

iOS

iOS10 以上使用XCUITest框架后,原生框架不支持XPATH,Appium进行了转换,速度很慢不建议使用。

AccessibilityId

Android

Android的content-desc属性对应AccessibilityId定位方式,这个content-desc属性专门为残障人士设置,如果这个属性不为空则推荐使用。

iOS

iOS的label和name属性都对应AccessibilityId定位方式,如果有则推荐使用。

AndroidUIAutomator

Android的源生测试框架的定位方式,定位速度快。推荐使用牢记常用的几种。

打开方法:

# 这个在运行时,调用的是Android自带的UI框架UiAutomator的Api
# 介绍几个简单常用的,text、className、resource-id
# text
# 匹配全部text文字
driver.find_element_by_android_uiautomator('new UiSelector().text("手机号")')
# 包含text文字
driver.find_element_by_android_uiautomator('new UiSelector().textContains("机")')
# 以text什么开始
driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("手")')
# 正则匹配text
driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^手.*")') # className
driver.find_elements_by_android_uiautomator('new UiSelector().className("android.widget.TextView")')
# classNameMatches
driver.find_elements_by_android_uiautomator('new UiSelector().classNameMatches("^android.widget.*")') # resource-id、resourceIdMatches 类似我们html id 这个可能重复,
 driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.syqy.wecash:id/et_content")') # description driver.find_element_by_android_uiautomator('new UiSelector().description("S 日历")') # descriptionStartsWith driver.find_element_by_android_uiautomator('new UiSelector().descriptionStartsWith("日历")') # descriptionMatches driver.find_element_by_android_uiautomator('new UiSelector().descriptionMatches(".*历$")') 

iOSPredicateString

仅支持iOS10以上,可以多个属性同时定位,推荐。(替代XPATH)

driver.find_elements_by_ios_predicate("label == '登录'")

driver.find_elements_by_ios_predicate("type='XCUIElementTypeOther' and name='联系人,标签, 第2个按钮,共3个'")

iOSUIAutomation

iOS9.3以下使用,现在已经废弃,iOSPredicateString代替了iOSUIAutomation

Appium定位方式总结的更多相关文章

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

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

  2. 七 APPIUM Android 定位方式

    1.定位元素应用元素   1.1通过id定位元素 Android里面定位的id一般为resrouce-id: 代码可以这样写: WebElement element = driver.findElem ...

  3. APPIUM Android 定位方式

    原文地址https://www.cnblogs.com/sundalian/p/5629500.html 1.定位元素应用元素 1.1通过id定位元素 Android里面定位的id一般为resrouc ...

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

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

  5. 六 APPIUM Android 定位方式

    文本转自:http://www.cnblogs.com/sundalian/p/5629500.html APPIUM Android 定位方式   1.定位元素应用元素 1.1通过id定位元素 An ...

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

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

  7. Appium ios新的定位方式FindsByIosNSPredicate (没有试 先记录在这里) 有个 driver.find_element_by_ios_uiautomation() 研究下 ios的定位

    这个定位方式需要用java-client -5.0.版本,4.x的版本没有这个定位方式 //输入账号和密码 driver.findElementByIosNsPredicate("value ...

  8. 6.1 python+appium元素定位方式(登录app)

    1.0.0     :常见的十种元素定位方式 .driver.find_element_by_id() #id定位 .driver.find_element_by_name() #name定位(已经凉 ...

  9. iOSNsPredicate Appium 定位元素

    Appium使用WebDriverAgent之后,新增了一种定位方法iOSNsPredicate,总结了一下使用方法: MobileElement photo = driver.findElement ...

随机推荐

  1. 529. Minesweeper扫雷游戏

    [抄题]: Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repre ...

  2. NGS NGS ngs(hisat,stringtie,ballgown)

    NGS ngs(hisat,stringtie,ballgown) #HISAT (hierarchical indexing for spliced alignment of transcripts ...

  3. [IBM][CLI Driver] SQL0270N 函数不受支持(原因码:"75")。 SQLSTATE=42997

    db2 update dbm cfg  using FEDERATED  yes 与 自动维护 (AUTO_MAINT) = ON 自动数据库备份 (AUTO_DB_BACKUP) = OFF 自动表 ...

  4. Calendar类常用需求方法

    经常处理一些日期相关的信息,Calendar类是处理日期的常用类,写下几个方法,不用重复造轮子了. 1.求上一天,下一天的日期 Date now = new Date();Calendar c = C ...

  5. C#List源码

    List // C# 源码 public class List<T> : IList<T>, System.Collections.IList, IReadOnlyList&l ...

  6. springsecurity 源码解读之 SecurityContext

    在springsecurity 中,我们一般可以通过代码: SecurityContext securityContext = SecurityContextHolder.getContext(); ...

  7. Reading | 《机器学习》(周志华)(未完待续)

    目录 I. 大师对人工智能和机器学习的看法 II. Introduction A. What is Machine Learning 什么是机器学习 B. Basic terms 基础术语 C. In ...

  8. pb数据导出

    pb数据导出(一) 1.在窗口新建用户事件  ue_export    2.事件调用函数 gf_dw_to_excel(THIS.dw_dict) 3.写函数 :boolean lb_setborde ...

  9. Lerning Entity Framework 6 ------ Complex types

    Complex types are classes that map to a subset of columns of a table.They don't contains key. They a ...

  10. 深圳scala-meetup-20180902(2)- Future vs Task and ReaderMonad依赖注入

    在对上一次3月份的scala-meetup里我曾分享了关于Future在函数组合中的问题及如何用Monix.Task来替代.具体分析可以查阅这篇博文.在上篇示范里我们使用了Future来实现某种non ...