【问题标题】:Left or Right swipe not working in appium for android app向左或向右滑动在 Android 应用程序的 appium 中不起作用
【发布时间】:2017-02-14 20:39:45
【问题描述】:

我正在尝试从第一个内容向右滑动(左侧没有内容) 到目前为止我在下面使用,但它不起作用,

public void swipeRightToLeft() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, Double> swipeObject = new HashMap<String, Double>();
    swipeObject.put("startX", 0.9);
    swipeObject.put("startY", 0.5);
    swipeObject.put("endX", 0.01);
    swipeObject.put("endY", 0.5);
    swipeObject.put("duration", 3.0);
    js.executeScript("mobile: swipe", swipeObject);

}

错误日志:org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

【问题讨论】:

    标签: java appium


    【解决方案1】:
    public void swipe(String direction, int offset, int time) {
    
            int y = appiumDriver.manage().window().getSize().getHeight();
            int x = appiumDriver.manage().window().getSize().getWidth();
            TouchAction touchAction = new TouchAction(appiumDriver);
            System.out.println(x + " " + y);
            System.out.println("Entering swipe");
            if ("right".equalsIgnoreCase(direction)) {
                System.out.println("Swipe Right");
                touchAction.press(x - offset, y / 2).moveTo(-(x - (2 * offset)), 0).release().perform();
            } else if ("left".equalsIgnoreCase(direction)) {
                System.out.println("Swipe Left");
                touchAction.press(offset, y / 2).moveTo((x - (2 * offset)), 0).release().perform();
            } else if ("up".equalsIgnoreCase(direction)) {
                System.out.println("Swipe Up");
                touchAction.press(x / 2, offset).moveTo(0, y - (2 * offset)).release().perform();
            } else if ("down".equalsIgnoreCase(direction)) {
                System.out.println("Swipe Down");
                touchAction.press(x / 2, y - offset).moveTo(0, -(y - (2 * offset))).release().perform();
            } else {
                throw new FrameworkException("Invalid direction");
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    or
        public void swipe(int startx, int starty, int endx, int endy, int duration) {
            TouchAction touchAction = new TouchAction(appiumDriver);
            System.out.println(startx + " " + starty);
            System.out.println("Entering swipe");
    
            System.out.println("Swipe from " + startx + " " + starty + "to" + endx + " " + endy);
            touchAction.press(startx, starty).waitAction(duration).moveTo(endx, endy).release().perform();
    starty + "to" + endx + " " + endy);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 2014-03-01
      • 2018-11-11
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多