【Mac + Appium + Python3.6(五)】之常用的Android自动化测试API总结

Github测试样例地址:https://github.com/appium-boneyard/sample-code/tree/master/sample-code/examples

 

①定位text,通过UiSelector定位

# text定位
self.d.find_element_by_android_uiautomator("new UiSelector().text(\"手机相册\")").click()

②中文输入问题,输入中文不显示:

appium自动化不能输入中文的解决办法

# 在参数设置中配置:

"unicodeKeyboard": True,
"resetKeyboard": True

如果一直弹unicode框提示重新安装,则参考我的另一篇文章《【Mac + Appium学习(二)】之Android自动化测试,appium-desktop配置和简易自动化测试脚本》(第一节第4小点)

# 配置完成之后再运行,还是采取UiSelector定位

self.d.find_element_by_android_uiautomator("new UiSelector().text(\"请输入内容\")").send_keys("安全隐患")

 但是又发现变为乱码了,参考解决办法:《appium+python自动化61-中文输入乱码问题解决

1.将unicodeKeyboard和resetKeyboard参数设置为True
2.手机设置设置-语言与输入框,Appium Android Input Manager for Unicode设置默认

③父子级定位

待续

④滑动:

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()

⑥其他常用元素定位请参考:

Github-Appium提问网址

Appium Appium Python API 中文版 By-HZJ*

appium+python自动化30-list定位(find_elements)

Appium python+appium 如何判定某元素存在

appium定位相同属性的元素

Appium+Python 自动化-appium常用元素定位方法

appium\selenium+python 滑动屏幕直至某元素出现

Appium学习路—Android定位元素与操作

Appium python自动化测试系列之元素的定位(六)

python+appium-desktop:安卓(android)7.0以上使用appium无法定位元素(无法refresh)且 无法运行脚本

Appium 在 Android UI 测试中的应用

 

posted @ 2018-11-23 14:14  Owen_ET  阅读(430)  评论(0编辑  收藏  举报