【问题标题】:Appium 1.6 , iOS 10: Swipe left on a specific elementAppium 1.6,iOS 10:在特定元素上向左滑动
【发布时间】:2016-12-01 07:18:50
【问题描述】:

我正在尝试使用 Appium 1.6 在 iOS 10 上的特定元素上向左滑动以显示删除按钮。

Touch Action and Swipe 向左滑动的代码在 appium 1.4 中运行良好,但问题是在我们迁移到 appium 1.6 后才出现的。

非常感谢任何帮助

【问题讨论】:

  • 能否请您分享您的代码以防万一您可以正常工作?我从一天开始就在苦苦挣扎,还没有运气。

标签: java appium


【解决方案1】:

我遇到了同样的问题,现在我找到了解决方案。

详情:

 Appium 1.6.4 beta 
 Java-Client-5.x beta

Appium 1.6.x - Swipe 已被移除,我们必须创建自己的 用于滑动的 TouchAction,在那个 waitAction() 使用负值将 执行快速滑动动作。例如 waitAction(-200)。

TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(-200).moveTo(x_travel, y_travel).release();
        action1.perform();

发表您的反馈。

【讨论】:

  • 我正在做如下 WebElement rowToSlide = driver.findElement(By.xpath("//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]//XCUIElementTypeTable[1]/XCUIElementTypeCell[1]") ); TouchAction swipe = new TouchAction(driver).press(rowToSlide, 250, 147) .waitAction(-200).moveTo(rowToSlide, 200, 147).release();刷卡。执行();但不是滑动,而是在元素上进行点击操作。我想向左滑动一行以取消隐藏其下方的按钮。请查看
  • 我在没有传递元素的情况下尝试了您的解决方案,但效果不佳。
  • TouchAction swipe = new TouchAction(driver).press( 250 , 147) .waitAction(-200).moveTo( 200, 147).release();刷卡。执行();试试这个?并且仍然存在问题将 moveTo(200,147) 更改为 moveTo(150,147)
  • github.com/appium/java-client/issues/580 ,我认为这是错误。你知道任何类似元素行为的开源项目吗,请分享
  • 不,我不知道有任何打开的项目已离开滑动。我当前的项目,我在 appium 1.5.3 中的 waitAction 中使用了 500 毫秒,升级到 1.6.3 后,左滑动(一种轻弹)不起作用,然后我尝试通过将 waitAction 值从 500 降低它来尝试解决方案使用适当的 x,y 和 x-offset,y-offset 处理负值的星星。
【解决方案2】:
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();
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

【讨论】:

    【解决方案3】:

    试试这个代码。调用 flick_left 并传递 WebElement。

    flick_left(元素)

    public void flick_left(WebElement flick_element) {
            Point location = flick_element.getLocation();
            Dimension size = flick_element.getSize();
    
                int flick_x, flick_y, flick_start_x, flick_end_x,flick_start_y,flick_end_y;  
    
                flick_x =size.getWidth();       
                flick_y = location.y + (size.getHeight()/2);
    
                flick_start_x = flick_x - (int)((double)flick_x*0.25);
                flick_end_x = flick_x -(int)((double)flick_x*0.55);
                swipe(flick_start_x, flick_y, flick_end_x, flick_y,-200);
    
    }
    
    
    
    public void swipe(int swipe_start_x, int swipe_start_y, int swipe_end_x, int swipe_end_y,int duration){
    
            int x = swipe_start_x;
            int y = swipe_start_y;
            int x_travel =  swipe_end_x-swipe_start_x;
            int y_travel =  swipe_end_y-swipe_start_y;
            TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(duration).moveTo(x_travel, y_travel).release();
            action1.perform();
    
    
        }
    

    【讨论】:

    • 请问哪个版本的appium服务端和客户端有这个新方法? github.com/appium/appium/issues/7815 ,也请查看此内容。似乎自过去几周以来,许多人都对滑动操作有疑问。
    • 这是我使用 TouchAction 为项目创建的自定义函数。 Appium 1.6.4 beta 和 java-client 5.0.0-BETA2
    • 你能不能告诉我,它对你有用吗?
    • 我尝试了类似的方法,得出的结论是appium服务器端存在错误。请参考github.com/appium/appium/issues/7914。如果重新添加了滑动方法,我感到很惊讶。请参阅问题 7815 以获取该参考
    • 谢谢。我去看看。
    猜你喜欢
    • 2016-10-07
    • 2019-05-26
    • 2015-05-11
    • 2017-02-22
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多