花里胡哨的的滑动-定位元素的方法

转载 滑动的同时找到元素

https://www.cnblogs.com/psklf/p/5290773.html

 
UiScrollable scrollView = new UiScrollable(new UiSelector().className("android.widget" +
                        ".ScrollView"));

        UiObject itemApps = scrollView.getChildByText(new UiSelector().className("android.widget" +
                ".TextView"),"Apps");
        itemApps.click();

new一个 Uiscrollable 的对象,然后用getChild 的方法找到子元素。

Appium (Python-client)

  def _find_by_scroll(self, item_name):

        item = self.driver.find_element_by_android_uiautomator(
            'new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "'
            + item_name + '")')
        item.click()

区别还是有的,用scrollable(true)找到对象,.instance(0) 再获取子元素

花里胡哨的的滑动定位  ---》点开连接跳转   转载

#后面的text查找条件可以用组合查找也可以用 textcontains 关键之查找text,一般查找条件使用text.....因为一般可滑动的区域id和class都是一样的...
driver.find_element_by_android_uiautomator
    ('new UiScrollable(new UiSelector().resourceId("被滑动区域最后一层的id")).scrollIntoView(new UiSelector().text("我们需要查找的元素text"))')





#后面的text查找条件可以用组合查找也可以用 textcontains 关键之查找text,一般查找条件使用text.....因为一般可滑动的区域id和class都是一样的...
driver.find_element_by_android_uiautomator
    ('new UiScrollable(new UiSelector().resourceId("被滑动区域最后一层的id")).scrollIntoView(new UiSelector().text(
"'+ va + '"
))')    红色的部分这样改写库传变量
        # driver.find_element_by_android_uiautomator
        #      ('new UiScrollable(new UiSelector().resourceId("com.southgnss.egstar3:id/listViewTemplateSelectItems")).scrollIntoView(new UiSelector().text("%s"))'%va)
        #

        item = self.driver.find_element_by_android_uiautomator(
            'new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "'+ va + '")')
        item.click()

  

原文地址:https://www.cnblogs.com/zhenyu1/p/12716601.html