Python Appium 元素定位方法简单介绍

Python  Appium  元素定位

常用的八种定位方法(与selenium通用)


Python Appium 元素定位方法简单介绍


Python Appium 元素定位方法简单介绍

id定位


Python Appium 元素定位方法简单介绍


Python Appium 元素定位方法简单介绍

name定位


Python Appium 元素定位方法简单介绍


Python Appium 元素定位方法简单介绍

Xpath定位

 如下图,使用 uiautomatorviewer.bat 获取页面元素

注意:SDK自带的uiautomatorviewer.bat无法获取xpath,需要替换一个jar包方可获取xpath。此jar包放到了QQ群:193056556中,有需要的可以进群自取。

self.driver.find_element_by_xpath("//android.widget.TextView[@text=' ']").click()


Python Appium 元素定位方法简单介绍

class_name定位

self.driver.find_element_by_class_name('android.view.View').click()

 (注:一般一个页面上的class属性不唯一,元素不唯一的话定位会报错了)


Python Appium 元素定位方法简单介绍

accessibility_id 定位

content-desc即是对应的 accessibility_id

driver.find_element_by_accessibility_id(u"我的").click()


Python Appium 元素定位方法简单介绍

android_uiautomator 定位

driver.find_element_by_android_uiautomator('new UiSelector().resourceId("username")').clear()

以下是代码实例


Python Appium 元素定位方法简单介绍