推荐Appium for Android元素定位方法
发布时间:2023-10-31 11:30:28 所属栏目:教程 来源:未知
导读: Appium定位元素的方法有很多,比如经常用的by_name、by_resource-id、by_classname
下面介绍下通过UI Automator方法来定位元素的方法,而且这些方法定位都比较准。
下面介绍下通过UI Automator方法来定位元素的方法,而且这些方法定位都比较准。
Appium定位元素的方法有很多,比如经常用的by_name、by_resource-id、by_classname 下面介绍下通过UI Automator方法来定位元素的方法,而且这些方法定位都比较准。 先假设我们通过UiAutomator定位到的元素部分属性如下: Index 1 Text xxx Resource-id android:id/text1 Class android.widget.TextView Content-desc xxx 一、 通过Text属性定位 直接通过text名称定位: Driver.find_element_by_android_uiautotmator(‘new UiSelector().text(“xxx”)’) 查找某个字符串包含有xxx的元素 Driver.find_element_by_android_uiautomator(‘new UiSelector().textContains(“xxx”)’) 某个以x打头的元素 Driver.find_element_by_android_uiautomator(‘new UiSelector().textStartWith(“x”)’) 通过Matches方法查找 Driver.find_element_by_android_uiautomator(‘new UiSelector().textMatches(“^xx.*”)’) 二、 通过class属性定位 通过class名称查找: driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("xxx")') 匹配text是xxx并且classname含有TextView的元素: driver.find_element_by_android_uiautomator('new UiSelector().classNameMatches(".*TextView$").text("xxx")') 三、 Xpath方法定位 通过同级元素定位同级元素,yyyy为同级元素节点text名称 driver.find_element_by_android_uiautomator('new UiSelector().text("xxx").fromParent(new UiSelector().text("yyyy"))') 通过父级元素定位子元素 ListView为父级节点classname driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.ListView").childSelector(new UiSelector().text("xxx"))') 四、 resourceId属性定位 通过resourceId定位: driver.find_element_by_android_uiautomator('new UiSelector().resourceId("android:id/text1")') 通过matches方法定位: driver.find_element_by_android_uiautomator('new UiSelector().resourceIdMatches(".*id/text1$")') 好了,先介绍很多吧,对元素进行操作的一些方法及获取元素的属性值都与web的类似。 (编辑:好传媒网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐