我无法使用 Java 在 Appium 中使滑动手势为我工作 [英] I can't make swipe gesture work for me in Appium using Java

查看:28
本文介绍了我无法使用 Java 在 Appium 中使滑动手势为我工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使滑动操作起作用.我确实浏览了几天的网络,发现了许多类似的问题,但没有有效的答案.我也尝试过 TouchAction 类,但效果不佳.

I can't made Swipe action work. I did browsed through the web for a few days and found many similar questions but there is no working answer. Also I have tried TouchAction class, doesn't work as well.

我有 Appium 版本 1.4.13 (Draco) 并使用 Java、TestNG 框架.

I have Appium Version 1.4.13 (Draco) and using Java, TestNG framework.

顺便说一句,我使用(您可以使用与拉动刷新相同的逻辑)进行滚动工作,这里是代码示例.

btw I made scrolling work using (you can use the same logic as a pull to refresh) here is code sample.

public void scrollUp() {
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    HashMap<String, String> scrollObject = new HashMap<String,String();
    scrollObject.put("direction", "up");
    scrollObject.put("element", listElements.get(1).getText());
    js.executeScript("mobile: scroll", scrollObject);
}

推荐答案

driver.context("NATIVE_APP"); 
        Dimension size = driver.manage().window().getSize(); 
        int startx = (int) (size.width * 0.8); 
        int endx = (int) (size.width * 0.20); 
        int starty = size.height / 2; 
        driver.swipe(startx, starty, endx, starty, 1000);

使用上面的代码.如果您希望向相反方向滑动,请将 startx 更改为 starty.

Use above code. Change startx to starty if you wish to swipe in opposite direction.

这篇关于我无法使用 Java 在 Appium 中使滑动手势为我工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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