如何在Android最新版本的Appium中执行上下滚动 [英] How to Perform Scroll up and Down in Android For Latest Version Appium

查看:95
本文介绍了如何在Android最新版本的Appium中执行上下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试上下滚动页面,有人可以帮我吗?我正在使用appium 1.6版.和Java客户端6.01对于最新版本,它不显示driver.scroll()方法或TouchAction action = new TouchAction(this.driver); action.press(startX,startY).moveTo(endX,endY).release().perform (); 它不执行新闻

I'm trying to scroll the page up and down could someone help me? I'm using appium version 1.6. and java client 6.01For latest Version it is Not Showing driver.scroll()methods or TouchAction action = new TouchAction (this.driver);action.press (startX, startY).moveTo (endX, endY) .release () .perform(); it is not performing press

推荐答案

这些方法未经测试,因为我目前没有需要滚动的测试应用程序,但我将它们组合在一起以供将来使用.对于每个滚动/滑动方向,我有两种方法-一种使用Appium,另一种使用javascript executor.我将仅显示下面的两个向下滚动例程,您应该能够仅通过这两个示例轻松确定如何编写其他方向.

These methods are untested as I currently have no test apps that require scrolling, but I've put these together for my own future potential use. I have two methods for each scroll/swipe direction - one using Appium and the other using javascript executor. I'll show just the two scroll down routines I have below, and you should be able to determine easily how to write the other direcections from just these two examples.

首先是Appium版本:

First, the Appium version:

public void scrollDown() throws Exception {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting y location set to 80% of the height (near bottom)
    int starty = (int) (size.height * 0.80);
    //Ending y location set to 20% of the height (near top)
    int endy = (int) (size.height * 0.20);
    //x position set to mid-screen horizontally
    int startx = size.width / 2;

    new TouchActions(driver)
            .down(startx, starty)
            .move(startx, endy)
            .release()
            .build()
            .perform();

}

现在对应的javascript版本:

Now the corresponding javascript version:

public void jsScrollDown() throws Exception {

    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    scrollObject.put("direction", "down");
    js.executeScript("mobile: scroll", scrollObject);

}

请记住,这些都没有经过测试,但是我使用的是从Appium网站本身收集的信息,因此它们都应该起作用.

Remember, neither of these are tested, but I am using the information I gathered from the Appium web site itself, so they should both work.

这篇关于如何在Android最新版本的Appium中执行上下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆