Appium滑动页面到底部的处理方式

2019-04-19  本文已影响0人  零下的雨

第一种页面底部显示滑动到底部了等信息
第二种页面中的resourceid相同,或者某个控件相同,能根据最后一个元素的text属性判断是否滑动到最后。

第一种代码示例:

boolean isSwipe = true;
String endString = "已加载全部数据";
String endString2 = "没有更多的数据";
// 滑动屏幕直到页面底部
while (isSwipe) {
    swipeToUp(androidDriver,200,1);//向上滑动屏幕
    String temp =androidDriver.getPageSource();
    if(temp.contains(endString) || temp.contains(endString2) )
        isSwipe = false;
    }

第二种代码示例:

// 获取所有信息,判断是否已经滑动到底部
   public static void getInfo() throws Exception {
       // 第一次滑动前,获取最后一个元素
       List<MobileElement> infolists1 = driver.findElementsById("resourceId");
       String originalinfo = infolists1.get(infolists1.size() - 1).getAttribute("text");
       System.out.println(originalinfo);
       Thread.sleep(1000);

       boolean isSwipe = true;
       String currentinfo;

       // 滑动
       while (isSwipe) {
           swipeToUp(1000);
           List<MobileElement> infolists2 = driver.findElementsById("resourceId");
           currentinfo= infolists2.get(infolists2.size() - 1).getAttribute("text");
           if (!currentinfo.equals(originalinfo))
               originalinfo= currentinfo;
           else {
               isSwipe = false;
               System.out.println(currentinfo);
               System.out.println("This is the buttom");
           }
       }
   }
上一篇下一篇

猜你喜欢

热点阅读