How to long press on android record button for a particular time in appium test, by java. I have tried 2 ways but both are not working at all, those are:
Way 1:
By pressRecBtn = By.id(“recorderButton”);
int x = 353; // x coordinate of device screen, get it after enabling the Show touch and Pointer location from developer option
int y = 980; // same as x
int timeInMs = 4000;
Action.longPress(driver.findElement(pressRecBtn)).longPress(x, y, timeInMs).perform();
Way2:
By pressRecBtn = By.id(“recorderButton”);
int timeInMs = 4000;
public TouchAction longPress(WebElement el, int duration) is deprecated and was replaced by public TouchAction longPress(WebElement el, Duration duration)
so:
new TouchAction(driver).longPress(element, Duration.ofMillis(duration)).release().perform()
After importing both suggestions: new TouchAction((PerformsTouchActions) driver).longPress((WebElement) recBtn, Duration.ofMillis(10000)).release().perform();
but its not working, showing the error: java.lang.ClassCastException: org.openqa.selenium.By$ById cannot be cast to org.openqa.selenium.WebElement
new TouchAction(driver).longPress(longPressOptions().withElement(element(camera)).withDuration(java.time.Duration.ofMillis(60000))).release().perform();
TouchAction t = new TouchAction(driver);
WebElement first = driver.findElementById("com.nra.productmarketingmaker:id/btnControlRight");
t.longPress(LongPressOptions.longPressOptions().withElement(element(first)).withDuration(Duration.ofSeconds(10))).release().perform();
I don’t know why it’s still tap for moment and release. any idea?