【问题标题】:Problem in longPress() on web element in apiumappium中webelement上长按()的问题
【发布时间】:2018-10-03 08:55:25
【问题描述】:

我在 apium 中为我的 web 元素使用 longpress(),并且我正在使用 ApiumDriver。 下面是代码和错误:

TouchAction ac=new TouchAction(driver);

ac.longPress((LongPressOptions) sm).perform().release();

其中 sm 是我的 web 元素,而错误如下:

无法将失败的 io.appium.java_client.android.AndroidElement 强制转换为 io.appium.java_client.touch.LongPressOptions

【问题讨论】:

    标签: automation appium long-press


    【解决方案1】:

    longPress 方法中,您必须使用ElementOption 传递AndroidElement

    import static io.appium.java_client.touch.offset.ElementOption.element;
    import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
    import io.appium.java_client.TouchAction;
    
        WebElement someElement = 
         driver.findElement(By.id("someID"));
      // WAY 1
       TouchAction ac=new TouchAction(driver);
       ac.longPress(element(someElement)).perform().release();
    
      // WAY 2
        TouchAction dragNDrop = new TouchAction(driver)
                .longPress(longPressOptions()
                        .withElement(element(someElement))
                        .withDuration(ofSeconds(2)))
                .perform().release();
    

    【讨论】:

      猜你喜欢
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2016-07-17
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多