Reputation: 1
appium=1.9.0
android devices
windows 10
Long press on a element is not working
I have already tried with :
<MobileElement longpress = (MobileElement) new WebDriverWait(driver, 30).
until(ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("msgContent")));
new Actions(driver).clickAndHold(longpress).perform();
error:
org.openqa.selenium.InvalidArgumentException: Parameters were incorrect. We wanted {"required":["actions"]} and you sent ["element"]
TouchAction action = new TouchAction(driver);
action.longPress((LongPressOptions) element).release().perform();
error:
java.lang.ClassCastException: com.sun.proxy.$Proxy16 cannot be cast to io.appium.java_client.touch.LongPressOptions
new TouchAction(driver).press(ElementOption.element(element)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(20))).release().perform();
error:
java.lang.ClassCastException: Cannot cast com.sun.proxy.$Proxy16 to org.openqa.selenium.internal.HasIdentity
Upvotes: 0
Views: 2125
Reputation: 11
The solution given works for IOS devices but not for android. For android you have to usegetCenter method instead of getLocation
Upvotes: 0
Reputation: 554
Instead of passing the element in "press" pass the coordinates of the element, check below code
Pass the x and y coordinates of the element in press
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();
this code should hold the element for 20 seconds
Upvotes: 1