Appium定位方式总结

news/2024/7/10 3:10:01 标签: 定位, vue, android, python, html
htmledit_views">
html" style="font-size: 16px;">

通过appium-desktophtml" title=定位>定位元素

ClassName

Android

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

iOS

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

ID

Android

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

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

XPATH

Android

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

iOS

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

AccessibilityId

Android

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

iOS

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

AndroidUIAutomator

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

打开方法:

 常用html" title=定位>定位方法

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

#组合html" title=定位>定位
self.driver.find_element_by_html" title=android>android_uiautomator('new UiSelector().resourceId("com.xueqiu.html" title=android>android:id/tab_name").text("我的")').click() 

#父子关系html" title=定位>定位
self.driver.find_element_by_html" title=android>android_uiautomator('new UiSelector().resourceId("com.xueqiu.html" title=android>android:id/title_container").childSelector(text("股票"))')

#兄弟关系html" title=定位>定位
self.driver.find_element_by_html" title=android>android_uiautomator('new UiSelector().resourceId("com.xueqiu.html" title=android>android:id/title_container").fromParent(text("股票"))')

#滚动查找
self.driver.find_element_by_html" title=android>android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("查找的元素文本").instance(0));')

iOSPredicateString

仅支持iOS10以上,可以多个属性同时html" title=定位>定位,推荐。(替代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


http://www.niftyadmin.cn/n/1345995.html

相关文章

持续集成:TeamCity 的安装和使用

TeamCity本文初衷 让大家了解持续集成(CI),以及入门了解 JetBrains 家的 TeamCity 的一些简单实用。TeamCity 的一些复杂使用我暂时也不会,一样也是要看文档的,所以不管怎样你都要养成看官网文档的习惯。TeamCity 和 J…

C语言如何检查编译错误,求大佬解答,为什么这个程序编译软件检查不出错误...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼#include#include /* malloc()等 */#include#include#include /* exit() */#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define OVERFLOW -2typedef int Status; /* Status是函数的类型,其值是函数结果状态代码&…

LPS发布3.0Beta1

Core 3.0b1 distribution http://www.laszlosystems.com/developers/download/files/lps-3.0b1-core.tar.gz

浅谈 DML、DDL、DCL的区别

一、DML DML(data manipulation language)数据操纵语言: 就是我们最经常用到的 SELECT、UPDATE、INSERT、DELETE。 主要用来对数据库的数据进行一些操作。 SELECT 列名称 FROM 表名称 UPDATE 表名称 SET 列名称 新值 WHERE 列名称 某值 INSERT INTO table_name (列…

c语言打印格式大全,C语言printf()输出格式大全zf

1. 转换说明符%a(%A)浮点数,十六进制数字和p-(P-)表示法(C99)%c字符%d有符号十进制整数%f浮点数(包括浮点数和doulbe)%e(%E)浮点指数输出[e-(E-)表示法]%g(%G…

[转贴]+[水贴]:) 好话连篇

经典的15句话 1,记住该记住的,忘记该忘记的。改变能改变的,接受不能改变的。 2,能冲刷一切的除了眼泪,就是时间,以时间来推移感情,时间 越长,冲突越淡,仿佛不断稀释的茶。…

libcurl c语言,C语言使用libcurl与json-c方法(代码实例)

C语言使用libcurl与json-c方法(代码实例)#include#include#include#include#include#includestruct curl_return_string {char *str;size_t len;size_t size;}; // 用于存curl返回的结果size_t _recive_data_from_http_api(void *buffer, size_t size, size_t nmemb, void *use…

性能调优之vmstat命令

vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、IO读写、CPU活动等进行监视。它是对系统的整体情况进行统计,不足之处是无法对某个进程进行深入分析。 指令所在路径:/usr/bin/vmstat 输出字段意义&a…