Github測試樣例地址:https://github.com/appium-boneyard/sample-code/tree/master/sample-code/exampleshtml
①定位text,經過UiSelector定位node
# text定位 self.d.find_element_by_android_uiautomator("new UiSelector().text(\"手機相冊\")").click()
②中文輸入問題,輸入中文不顯示:python
《appium自動化不能輸入中文的解決辦法》android
# 在參數設置中配置: "unicodeKeyboard": True, "resetKeyboard": True
若是一直彈unicode框提示從新安裝,則參考個人另外一篇文章《【Mac + Appium學習(二)】之Android自動化測試,appium-desktop配置和簡易自動化測試腳本》(第一節第4小點)git
# 配置完成以後再運行,仍是採起UiSelector定位 self.d.find_element_by_android_uiautomator("new UiSelector().text(\"請輸入內容\")").send_keys("安全隱患")
可是又發現變爲亂碼了,參考解決辦法:《appium+python自動化61-中文輸入亂碼問題解決》github
1.將unicodeKeyboard和resetKeyboard參數設置爲True 2.手機設置設置-語言與輸入框,Appium Android Input Manager for Unicode設置默認
③父子級定位安全
待續app
④滑動:學習
《appium\selenium+python 滑動屏幕直至某元素出現》測試
⑤獲取相同元素的最後一個元素定位:
# 元素1 list = self.d.find_elements_by_id("cn.sqm.citymine_safety:id/item_tv_personnel_name") num = len(list) list[num-num].click() self.d.find_element_by_android_uiautomator("new UiSelector().text(\"xxx\")").click() self.d.find_element_by_id("cn.sqm.citymine_safety:id/tv_complete").click()
# 元素2 list = self.d.find_elements_by_id("cn.sqm.citymine_safety:id/item_tv_personnel_name") num = len(list) list[num-1].click()
⑥其餘經常使用元素定位請參考:
《Appium Appium Python API 中文版 By-HZJ》*
《appium+python自動化30-list定位(find_elements)》
《Appium python+appium 如何斷定某元素存在》
《Appium+Python 自動化-appium經常使用元素定位方法》
《appium\selenium+python 滑動屏幕直至某元素出現》
《Appium python自動化測試系列之元素的定位(六)》
《python+appium-desktop:安卓(android)7.0以上使用appium沒法定位元素(沒法refresh)且 沒法運行腳本》