1、id定位
该控件的对应ID属性为:“resoerce-id” :“com.android.settings:id/title”
使用方法:bluetooch = driver.find_element_by_id("com.android.settings:id/title")
2、classname定位
该控件对应的classname属性为:“class”:“android.widget.TextView”
使用方法:bluetooch = driver.find_element_by_class_name("android.widget.TextView")
3、XPath定位
使用方法:driver.find_element_by_xpath('//*[@text="蓝牙"]')
4、AccessibilityId定位(以手机QQ登录界面为例)
该控件对应的AccessibilityId属性为:“content-desc”:"请输入QQ号码或手机或邮箱"
使用方法:driver.find_element_by_accessibility_id("请输入QQ号码或手机或邮箱")
AccessibilityId定位.png
5、AndroidUiAutomator定位
AndroidUiAutomator属于Appium的拓展定位方法,可以选择id、name、classname作为传入的字符串,但是要保证该种定位方式的唯一性
使用方法:
driver.find_element_by_android_uiautomator("new UiSelector().text("蓝牙")")
driver.find_element_by_android_uiautomator("new UiSelector().description("请输入QQ号码或手机或邮箱")")
driver.find_element_by_android_uiautomator("new UiSelector().resourceId("com.android.settings:id/title")")