Click and Hold touch action in Appium

I want to click and hold the object then take a screen shot before releasing the object, is it possible in Appium ?.

Yes, it is possible.

Appium version : 1.8.1
Java client : 6.1.0

public void longPressScreenshot(MobileElement element,String screenshotName){
new TouchAction<>(driver).longPress(longPressOptions()
.withElement(element(element))).waitAction(waitOptions(Duration.ofSeconds(3)))
.moveTo(ElementOption.element(element))
.perform().release();
captureScreenshot(screenshotName);
}

public void captureScreenshot(String screenshotName) {
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String filePath = System.getProperty(“user.dir”) + File.separator + “screenshots” + File.separator +screenshotName+".png";
try {
FileUtils.copyFile(srcFile, new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
}

com-video-to-gif

1 Like

Is this possible to do in Python?

Hello,

I want to touch and hold and at the same time, speak something (like we need to do for Alexa). Is it possible for Appium ?

Regards,
Vishnu