[TOC]
## 使用uiautomator定位 `driver.find_element_by_android_uiautomator(uia_string)`
*uia_string:uia_string - The element name in the Android UIAutomator library* 使用UIAutomator元素屬性名稱來定位
### 根據 resourceId 屬性 定位
```
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("%s")')
```
舉例:如下圖,點擊頂部掃碼器:

**對應uiautomator名稱:“resource-id”:**
```
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.rfchina.app.supercommunity:id/square_title_btn_scan")').click()
```
>[warning] 選擇resource-id 定位需要特別注意,界面中 resource-id 不是唯一的,有可能存在很多控件的resource-id是相同的。
### 根據 text、description、className、index屬性定位
```
# 根據 text 定位
driver.find_element_by_android_uiautomator('new UiSelector().text("%s")') #對應uiautomator名稱:“text”
# 根據 description 定位
driver.find_element_by_android_uiautomator('new UiSelector().description("%s")') # 對應uiautomator名稱:“content-desc”
# 根據 className 定位
driver.find_element_by_android_uiautomator('new UiSelector().className("%s")') # 對應uiautomator名稱:“class”
# 根據 index 定位
driver.find_element_by_android_uiautomator('new UiSelector().index("%s")') # 對應uiautomator名稱:“index”
```
>[warning] 選擇className 定位需要特別注意,界面中 class 往往都不是唯一的,大量控件的class會一樣。
<br>
## 根據content-desc定位 `driver.find_element_by_accessibility_id()`
## 根據xpath定位 `driver.find_element_by_xpath()`
```python
from appium import webdriver
import time
desired_caps = {
"appPackage": "com.rfchina.app.supercommunity",
"appActivity": "com.rfchina.app.supercommunity.client.StartActivity",
"platformName": "Android",
"deviceName": "Android Emulator"
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(5)
driver.find_element_by_id("com.rfchina.app.supercommunity:id/img_serivce_communities_layout").click()
```