如何在appium-android中长按元素?

时间:2019-05-01 08:24:17

标签: appium-android

appium = 1.9.0
android设备
Windows 10

长按元素不起作用

我已经尝试过:

  1. <MobileElement longpress = (MobileElement) new WebDriverWait(driver, 30).
        until(ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("msgContent")));
    new Actions(driver).clickAndHold(longpress).perform();
    

    错误:

  

org.openqa.selenium.InvalidArgumentException:参数为   不正确我们想要{“ required”:[“ actions”]},然后您发送了[“ element”]

  1. TouchAction action = new TouchAction(driver);
    action.longPress((LongPressOptions) element).release().perform();
    

    错误:

  

java.lang.ClassCastException:com.sun.proxy。$ Proxy16无法转换为   io.appium.java_client.touch.LongPressOptions

  1. new TouchAction(driver).press(ElementOption.element(element)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(20))).release().perform();
    

错误:

  

java.lang.ClassCastException:无法将com.sun.proxy。$ Proxy16强制转换为   org.openqa.selenium.internal.HasIdentity

1 个答案:

答案 0 :(得分:0)

与其在“ press”中传递元素,不传递元素的坐标,而是检查以下代码

  1. 首先找到您的元素
  2. 传递按下元素的x和y坐标

    <Grid item key={item}>
    

此代码应将元素保留20秒