基础定位方法 ID、CLASS_NAME、ACCESSIBILITY_ID(移动端特有的定位方法)
Appium从版本1.5以后,不支持NAME定位。
高级定位方法 XPATH、ANDROID_AUTOMATOR(移动端特有的定位方法)

ID
截图 元素
image.png com.android.email:id/account_email
或
account_email
说明:如果resource-id属性值是“包名:id/字符串”的格式,则可以简化为只是用/后的那个字符串作为定位参数数据。
```python

from appium.webdriver.common.mobileby import MobileBy driver.find_element(MobileBy.ID,’account_email’).click()

或

driver.find_element(MobileBy.ID,’com.android.email:id/account_email’)

  1. | |
  2. <a name="crzuN"></a>
  3. ##### CLASS_NAME
  4. | 截图 | 元素 |
  5. | --- | --- |
  6. | ![image.png](https://cdn.nlark.com/yuque/0/2023/png/25474243/1672756488255-7a053121-8c26-48aa-9ac6-2044198522cb.png#averageHue=%23f1ede9&clientId=uffc0f323-30c3-4&from=paste&height=782&id=oG9NF&originHeight=977&originWidth=1584&originalType=binary&ratio=1&rotation=0&showTitle=false&size=162777&status=done&style=none&taskId=u9e7838fb-03ec-4d4d-b461-1ab6abf7eaa&title=&width=1267.2) | android.widget.EditText<br /><br />说明:类名是描述控件类型的一个字符串,不同的元素,类名不同,如果当前类型只有一个元素,可以用class。 |
  7. | ```python
  8. from appium.webdriver.common.mobileby import MobileBy
  9. driver.find_element(MobileBy.CLASS_NAME,'android.widget.EditText')

| | | image.png | android.widget.TextView[0] # 下一步
android.widget.TextView[1] # 手动设置
当前页面存在多种相同的元素,,find_element方法会返回符合条件的一个元素,如果想要定位则可以用find_elements方法获取全部符合条件的元素,然后根据索引号去定位对应的元素。 | | ```python from appium.webdriver.common.mobileby import MobileBy driver.find_elements(MobileBy.CLASS_NAME,’android.widget.TextView’)[0] driver.find_elements(MobileBy.CLASS_NAME,’android.widget.TextView’)[1]

  1. | |
  2. <a name="Iwaae"></a>
  3. ##### ACCESSIBILITY_ID
  4. | 截图 | 元素 |
  5. | --- | --- |
  6. | ![image.png](https://cdn.nlark.com/yuque/0/2023/png/25474243/1672757295698-64847773-ca24-4971-9556-adc881c2f1ad.png#averageHue=%23f2f1f0&clientId=uffc0f323-30c3-4&from=paste&height=782&id=uc102cc5c&originHeight=977&originWidth=1584&originalType=binary&ratio=1&rotation=0&showTitle=false&size=180704&status=done&style=none&taskId=u0223f037-c1e3-424f-b912-fd88acaa8b6&title=&width=1267.2) | 手机号输入框 |
  7. | ```python
  8. from appium.webdriver.common.mobileby import MobileBy
  9. driver.find_element(MobileBy.ACCESSIBILITY_ID,"手机号输入框")

| |