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)且 没法运行脚本》