IOS元素定位对应关系

resource-id也称为id,resource-id是唯一的

元素定位

agree_continue_id = "com.baidu.searchbox:id/positive_button"

WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.ID, agree_continue_id)))

driver.find_element_by_id(agree_continue_id).click(

AccessibilityId也称为content-desc

元素定位

tiku_AccessibilityId = "题库"

WebDriverWait(driver, 10, 1).until(EC.visibility_of_all_elements_located((MobileBy.ACCESSIBILITY_ID, tiku_AccessibilityId)))

driver.find_element_by_accessibility_id(tiku_AccessibilityId).click()

比如xpath中同时包含class和text两个属性

元素定位

agree_continue_xpath = "//*[@class='android.widget.Button' and @text='同意并继续']"

WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.XPATH, agree_continue_xpath)))

driver.find_element_by_xpath(agree_continue_xpath).click()

根据text属性为"请输入手机号"查找元素。

  1. ele = self.driver.find_element_by_android_uiautomator('new UiSelector().text("请输入手机号")')

  2. ele.send_keys("123")

5.3 textStartsWith定位

以text什么开始

driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("请输入")')

5.4 textMatches 正则匹配查找

textMatches故名思义就是通过正则的来进行查找定位,他也是通过text的属性来进行正则匹配,我们直接看代码:

ele = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^请输入手.*")')

ele.send_keys("123")

5.5 resourceID定位

resourceId定位和appium封装好的id定位是一样的,只是这里将写法变成了uiautomator的写法而已,看下面代码

ele = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/et_phone_edit")')

ele.send_keys('234')

5.6 resourceIDMatches 定位

通过id进行正则匹配定位

ele = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceIdMatches(".+et_phone_edit")')

ele.send_keys('234')

5.7 className定位

通过调用android uiautomator使用className进行定位

ele = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.EditText")')

ele.send_keys('234')

5.8 classNameMatches定位

通过className正则匹配进行定位

ele = self.driver.find_element_by_android_uiautomator('new UiSelector().classNameMatches (".*EditText")')

ele.send_keys('234')

5.9 组合定位

#组合定位

self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/tab_name").text("我的")').click()

或者

组合定位,一般组合用id,class,text这三个属性会比较好一点

id+class 属性组合

id_class = 'resourceId("com.xyh.commerce:id/ll_personal").className("android.widget.LinearLayout")'

driver.find_element_by_android_uiautomator(id_class).click()

5.10 父子关系、兄弟关系定位

#父子关系定位

self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/title_container").childSelector(text("股票"))')

#兄弟关系定位

self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/title_container").fromParent(text("股票"))')

5.11 滚动查找

#滚动查找#滚动查找
self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("查找的元素文本").instance(0));')

相关推荐
Kevin Coding2 小时前
Flutter使用Flavor实现切换环境和多渠道打包
android·flutter·ios
wn5312 天前
【浏览器 - Mac实时调试iOS手机浏览器页面】
前端·macos·ios·智能手机·浏览器
小鹿撞出了脑震荡3 天前
Effective Objective-C 2.0 读书笔记—— 方法调配(method swizzling)
ios·objective-c·swift
小鹿撞出了脑震荡3 天前
Effective Objective-C 2.0 读书笔记—— 消息转发
ios·objective-c·swift
一丝晨光4 天前
Cocoa和Cocoa Touch是什么语言写成的?什么是Cocoa?编程语言中什么是框架?为什么苹果公司Cocoa类库有不少NS前缀?Swift编程语言?
macos·ios·objective-c·cocoa·swift·uikit·cocoa touch
LucianaiB6 天前
字节iOS面试经验分享:HTTP与网络编程
网络·ios·面试
黄油奥特曼6 天前
Flutter解决macbook M芯片Android Studio中不显示IOS真机的问题
flutter·ios·android studio·m芯片
taopi20247 天前
ios打包:uuid与udid
ios·iphone·ipad
小鹿撞出了脑震荡7 天前
Effective Objective-C 2.0 读书笔记——关联对象
开发语言·ios·objective-c
小鹿撞出了脑震荡7 天前
Effective Objective-C 2.0 读书笔记—— objc_msgSend
ios·objective-c·xcode