Skip to main content

How to use touch action in Appium

How to use touch action in Appium[Up to date: java-client 6.x.x]

Assuming we have 
MobileElement myElement;
int xPoint = 282;
int yPoint = 808;
int duration = 1000; //in milliseconds, change the value as per the required

Tap on the Element with element locator(id/xpath): new TouchAction((AndroidDriver)driver).tap(tapOptions().withElement(element(myElement))).perform();

Tap on the element with Coordinates: new TouchAction((AndroidDriver)driver).tap(point(xPoint, yPoint)).perform();

Tap on the Element using coordinates relative to element: new TouchAction((AndroidDriver)driver).tap(tapOptions().withElement(element(myElement, xPoint, yPoint))).perform();

LongPress on the Element with element locator(id/xpath): new TouchAction((AndroidDriver)driver).longPress(longPressOptions().withElement(element(myElement))).release().perform();

LongPress on the Element with element locator(id/xpath) and Duration: new TouchAction((AndroidDriver)driver).longPress(longPressOptions().withElement(element(myElement)).withDuration(Duration.ofMillis(duration))).release().perform();

LongPress on the element with coordinates: new TouchAction((AndroidDriver)driver).longPress(point(xPoint, yPoint)).release().perform();

LongPress on coordinates with duration:

Note: How to find X and Y coordinate from android phone?

Comments

Popular posts from this blog

How to click/tap on the element by using X and Y coordinate in Appium?

How to click/tap on the element by using X and Y coordinate in Appium? [ Up to date:  java-client 6.x.x ] If don't have unique ID or any other locator of any element, then we can click on the element by using x and y coordinate. For that we have to fine X and Y coordinate first. How to find X and Y coordinate from android phone? Go to 'Settings' Go to 'Developer options' (Additional / Advanced settings > Developer options) Enable 'Show taps' and 'Pointer location' (Below the INPUT title) For example, we want to automate Calculator app Open the Calculator app and tap on the element and collect the X and Y coordinate like below image Use above X and Y coordinate int x = 282 ; int y = 808 ; new TouchAction((AndroidDriver) driver ).tap( point (x, y)).perform();

How to handle native Android keyboard by using Appium?

How to handle native Android keyboard by using Appium?[ Up to date: java-client 6.x.x ] We are going to tap on the enter button For WebDriver ((AndroidDriver) driver ).pressKey( new KeyEvent(AndroidKey. ENTER )); For AndroidDriver driver .pressKey( new KeyEvent(AndroidKey. ENTER ));   For more KeyEvert please follow the link Android KeyEvent

How to perform Vertical and Horizontal swipe in Appium?

How to perform Vertical and Horizontal swipe in Appium?[ Up to date:  java-client 6.x.x ] In Android application Automation, sometimes we need to scroll up/down and swipe left/right, in this tutorial I'm trying to show how to perform them. 1. For vertical swiping use below method public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception { Dimension size = driver.manage().window().getSize(); int anchor = ( int ) (size. width * anchorPercentage); int startPoint = ( int ) (size. height * startPercentage); int endPoint = ( int ) (size. height * finalPercentage); new TouchAction(driver).press(PointOption. point (anchor, startPoint)).waitAction(WaitOptions. waitOptions (Duration. ofMillis (duration))).moveTo(PointOption. point (anchor, endPoint)).release().perform(); } and call the above method like below Scroll up: swipeVertical ((AppiumDriver) dri...