如何使用java在混合应用程序中的appium中向下滑动页面。

时间:2017-01-02 15:41:52

标签: java appium

我无法使用java在appium中的混合应用程序中向下滚动页面。我正在使用Appium v​​1.6.3

4 个答案:

答案 0 :(得分:0)

您可以使用滑动方法从下往上滑动。
 ds.swipe(startx,starty,endx,endy,500);
要么
你可以使用scrollto("元素名称")

答案 1 :(得分:0)

因为它是混合应用程序,所以首先我们必须更改为Native_APP然后我们必须应用下面的代码

Dimension  size = driver.manage().window().getSize();
           System.out.println(size);

           //Find swipe start and end point from screen's with and height.
           //Find starty point which is at bottom side of screen.
           int starty = (int) (size.height * 0.70);
           //Find endy point which is at top side of screen.
           int endy = (int) (size.height * 0.20);
           //Find horizontal point where you wants to swipe. It is in middle of screen width.
           int startx = size.width / 2;
           System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);

答案 2 :(得分:0)

这是我尝试向下滚动侧边菜单并找到注销

的方法

//向下滑动侧边菜单,然后点击退出

 @Test
         public void T4b_logout() throws InterruptedException{  
              size = driver.manage().window().getSize(); //Get the size of screen.
              System.out.println(size);                   
              int starty = (int) (size.height * 0.80);//Find starty point which is at bottom side of screen.
              int endy = (int) (size.height * 0.20);  //Find endy point which is at top side of screen.          
              int startx = size.width / 2; //Find horizontal point where you wants to swipe. It is in middle of screen width.       
              System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);   // int startx = size.width;
              driver.swipe(startx, starty, startx, endy, 3000);//Swipe from Bottom to Top.
              Thread.sleep(2000);
              driver.findElement(By.name("Logout")).click();
              driver.findElement(By.xpath("//android.widget.Button[@text='Ok']")).click();

         }

答案 3 :(得分:0)

以下是向下滑动的代码。交换开始,结束值以便向上滑动。

public void scrollDown(AndroidDriver driver,int swipeTimes, int durationOfSwipe){
        Dimension dimension = driver.manage().window().getSize();

        for (int i=0; i<=swipeTimes;i++){

            int start = (int) (dimension.getHeight() * 0.8);
            int end = (int) (dimension.getHeight() * 0.1);
            int x = (int) (dimension.getWidth()*.5);

            driver.swipe(x, start, x, end, durationOfSwipe);
        }
    }