【问题标题】:How to tap and hold (Long press) using appium for Android?如何使用适用于 Android 的 appium 点击并按住(长按)?
【发布时间】:2015-05-31 15:04:57
【问题描述】:

是否有任何代码可以点击并按住 Appium?我用python,有什么命令支持吗?

双击我使用了两次点击元素,点击并按住我没有得到任何解决方案

【问题讨论】:

    标签: appium


    【解决方案1】:

    需要通过驱动

    TouchAction action = new TouchAction(driver);
    action.longPress(webElement).release().perform();
    

    【讨论】:

    • action.longPress(webElement) 不起作用,它需要 longPressOptions 如果我通过 MobileElement 或 WebElement,则会出现以下错误:无法解析方法 'longPress(io.appium.java_client.MobileElement)'
    【解决方案2】:

    是的,您可以使用 TouchAction 类来长按任何元素。试试这个:

    TouchAction action = new TouchAction();
    action.longPress(webElement).release().perform();
    

    【讨论】:

      【解决方案3】:

      在以下最新的 Java 客户端版本中可以使用。

      AndroidTouchAction touch = new AndroidTouchAction (driver);
      touch.longPress(LongPressOptions.longPressOptions()
                      .withElement (ElementOption.element (element)))
                    .perform ();
      
      System.out.println("LongPressed Tapped");
      

      【讨论】:

      • 默认长按时间是多少?
      【解决方案4】:

      这是Java Client: 5.0.4的更新

      WebElement recBtn = driver.findElement(MobileBy.id("img_button"));
      new TouchAction((MobileDriver) driver).press(recBtn).waitAction(Duration.ofMillis(10000)).release().perform();
      

      【讨论】:

        【解决方案5】:

        应该是这样的。持续时间以毫秒为单位计算,因此需要乘以 1000 为 1 秒。

        TouchAction action = new TouchAction(driver);
        action.longPress(webElement,duration*1000).release().perform();
        

        【讨论】:

          【解决方案6】:

          这行得通:

          TouchActions action = new TouchActions(driver);
          action.longPress(element);
          action.perform();
          

          【讨论】:

            【解决方案7】:

            以下工作:

                MobileElement longpress = driver.findElement({element find strategy})
                LongPressOptions longPressOptions = new LongPressOptions();
                longPressOptions.withDuration(Duration.ofSeconds(3)).withElement(ElementOption.element(longpress));
                TouchAction action = new TouchAction(driver);
                action.longPress(longPressOptions).release().perform();
            

            【讨论】:

              【解决方案8】:

              一旦您确定了要长按的 pageElement。

              //pageElement
              
              editPreferenceButton = driver.whatever 
              
              //code for waiting for display of element
              
              waitForDisplayed(editPreferenceButton, 10)
                      
              //this line is not required, keeping it here for easy readability
              
              MobileElement longpress = editPreferenceButton;
              
              //use the below code, it will do the trick, credits to wherever i found this
              
              LongPressOptions longPressOptions = new LongPressOptions();               longPressOptions.withDuration(Duration.ofSeconds(3)).withElement(ElementOption.element(longpress));
              TouchAction action = new TouchAction(driver);
              action.longPress(longPressOptions).release().perform();}
              

              【讨论】:

                猜你喜欢
                • 2011-03-22
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2020-02-15
                • 2020-06-27
                • 1970-01-01
                • 2012-03-24
                相关资源
                最近更新 更多