【问题标题】:Difference between Press and Tap touch action in Appium?Appium中的Press和Tap触摸动作之间的区别?
【发布时间】:2020-05-01 22:53:18
【问题描述】:

我想知道在使用 Appium Driver 时点击和按下元素之间的区别。

我能够理解 Click 和 Tap 之间的区别,但无法理清关于 Tap 和 Press 的概念。我能够确定的唯一区别是 tap 同时适用于位置和元素,但 press 似乎只适用于位置。

但即便如此,我也可以使用点击来处理位置点击和元素点击。为什么我们需要明确地按下? 它们似乎在 UI 上执行相同的功能。有人可以向我解释一个用例,我们需要明确地点击而不是按下,反之亦然。

以下是我用于两者的代码:

敲击:

t.tap(tapOptions().withElement(ElementOption.element(MY_WEBELEMENT))).perform();

按下:

t.press(PointOption.point(0, 1200)).release().perform();

我是 Appium 测试的新手,并且仍在努力改进这些基础知识。随时指导我了解任何现有的文档。

【问题讨论】:

    标签: appium appium-android


    【解决方案1】:

    TapPress 都适用于元素和坐标。看看吧。

    假设我有这个 Mobile 元素、坐标和持续时间。

    MobileElement myElement;
        int xPoint, int yPoint;
        int duration = XXXX; //in miliseconds
    

    点击元素:

    new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement))).perform();
    

    点击坐标:

    new TouchAction(localdriver).tap(point(xPoint, yPoint)).perform();
    

    使用相对于元素的坐标点击元素:

    new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement, xPoint, yPoint))).perform();
    

    长按元素:

    new TouchAction(localdriver).longPress(longPressOptions().withElement(element(myElement))).release().perform();
    

    长按元素持续时间:

    new TouchAction(localdriver).longPress(longPressOptions().withElement(element(myElement)).withDuration(Duration.ofMillis(duration))).release().perform();
    

    长按坐标:

    new TouchAction(localdriver).longPress(point(xPoint, yPoint)).release().perform();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 2017-12-29
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      相关资源
      最近更新 更多