appium-android - 如何在appium-android中长按元素?
问题描述
appium=1.9.0
安卓设备
windows 10
长按元素不起作用
我已经尝试过:
<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"]
TouchAction action = new TouchAction(driver); action.longPress((LongPressOptions) element).release().perform();
错误:
java.lang.ClassCastException:com.sun.proxy.$Proxy16 无法转换为 io.appium.java_client.touch.LongPressOptions
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
解决方案
而不是在“按下”传递元素传递元素的坐标,检查下面的代码
- 首先找到你的元素
在 press 中传递元素的 x 和 y 坐标
WebElement ele = driver.findElement(BY.xpath("your_element_xpath")); Point location = ele.getLocation(); new TouchAction(driver).press(PointOption.point(location.getX(), location.getY())).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(20))).release().perform();
此代码应将元素保留 20 秒
推荐阅读
- c - Function who counts the number of positive, negative,null numbers of an Array "using pointers"
- git - Trying to revert back to older version of commit
- python - Pandas dataframe to Snowflake with lowercase columns
- computer-vision - Incremental Learning in Yolo or in general
- java - 如何使用 Fake appupdatemanager 进行测试?
- java - 迭代地更改 Kafka Stream SessionWindows 的持续时间
- swift - Swift 5 中 UNUserNotificationCenter .requestAuthorization 的单元测试
- c# - 递增 LinkedList 的前“n”个整数
使用 Linq - php - 在 laravel 中使用队列的电子邮件之间的延迟
- r - R中的决策树图工具