【问题标题】:How to Perform Scroll up and Down in Android For Latest Version Appium如何在 Android 中为最新版本的 Appium 执行向上和向下滚动
【发布时间】:2019-01-03 09:19:02
【问题描述】:

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

【问题讨论】:

    标签: android webdriver appium


    【解决方案1】:

    这些方法未经测试,因为我目前没有需要滚动的测试应用程序,但我已将它们放在一起以备将来使用。对于每个滚动/滑动方向,我有两种方法 - 一种使用 Appium,另一种使用 javascript 执行器。我将只展示下面的两个向下滚动例程,您应该能够从这两个示例中轻松确定如何编写其他方向。

    一、Appium版本:

    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版本:

    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 网站本身收集的信息,因此它们应该都可以工作。

    【讨论】:

    • 我收到此错误 java.lang.AbstractMethodError。
    • 你运行的是什么版本的appium server和appium java client?
    • Appium 1.6ver和java客户端6.1版本
    • 你是通过桌面版还是通过java代码启动Appium Server?
    • 仅通过桌面版
    猜你喜欢
    • 2019-12-24
    • 2018-12-03
    • 2016-05-16
    • 2018-01-01
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多