【问题标题】:Right left swipe in appium在appium中左右滑动
【发布时间】:2019-10-14 17:45:07
【问题描述】:

如何在最新版本的 appium 中进行左右操作,因为我们在新的 appium 版本中没有 swipe(driver.swipe) 方法

public DailyPicksPage swipeDailyPicksCard() throws Exception {
        Dimension size = agent.getMobileDriver().manage().window().getSize();
        System.out.println("Dimensions of the screen" + size);
        int startX = (int) (size.width * 0.80);
        int endX = (int) (size.width * 0.20);
        int width = size.width;
        int duration = 2000;
        int height = size.height;
        int pressHeight = (int) (height * 0.80);
        new TouchAction(agent.getMobileDriver()).press(PointOption.point(startX, pressHeight)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration))).moveTo(PointOption.point(endX, pressHeight)).release().perform();
        return new DailyPicksPage(params, agent);
    }

【问题讨论】:

    标签: selenium-webdriver appium ui-automation


    【解决方案1】:

    您可以使用 io.appium.java_client.TouchAction

    创建自定义滑动方法
    public void horizontalSwipeByPercentage(double startPercentage, double endPercentage, double anchorPercentage, AppiumDriver<MobileElement> driver) {
        Dimension size = driver.manage().window().getSize();
        int anchor = (int) (size.height * anchorPercentage);
        int startPoint = (int) (size.width * startPercentage);
        int endPoint = (int) (size.width * endPercentage);
    
        new TouchAction(driver)
                .press(PointOption.point(startPoint, anchor))
                .waitAction(WaitOptions.waitOptions(ofSeconds(1)))
                .moveTo(PointOption.point(endPoint, anchor))
                .release().perform();
    }
    

    【讨论】:

    • 上述自定义方法中anchor的作用是什么?
    • 对于水平滑动,锚点是固定的y坐标位置。
    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    相关资源
    最近更新 更多