Appium自动化测试-------滑动屏幕如何定位定位元素

使用API Demo做演示,进入APIDemo中Views,然后滑屏寻找“Popup Menu”进行点击操作,但是不知道滑动多久,才能看到这个元素,该怎么定位呢?


Appium自动化测试-------滑动屏幕如何定位定位元素

可以利用Android的UIAutomator进行滑屏操作,这时候需要使用AndroidDriver,另外定位元素可以使用UiScrollable:

appium官方说明文档:http://appium.io/docs/en/commands/element/find-elements/
 

Appium自动化测试-------滑动屏幕如何定位定位元素

python代码:

self.driver.find_element_by_android_uiautomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(\"Popup Menu\").instance(0))")

这里大概定位的方法就是,先用new UiSelector().scrollable(true).instance(0)判断是否可以滑动,找到ListView,然后用scrollIntoView(new UiSelector().text(“WebView”).instance(0)滑动找到对应定位属性的元素。

Appium自动化测试-------滑动屏幕如何定位定位元素