Appium & Java : how to perform fast click actions?

Hi All,
I would like to perform 10 quick clicks action on a button in an Android app (prefer 0.5s), but following 10 clicks’ gap is too long (approx 1.5 sec gap). Wondering what is the proper way to shorten the gap between each click in Appium Java?
I’ve tried findElement by xpath, but still no luck, wondering if there’s any other way? or it’s just simply the limitation of Appium for now? (btw i’m using io.appium 6.0.0-BETA4)
THANK YOU in advance!

MobileElement element = driver.findElement(By.id(“btnA”));
for(int i=1; i<11; i++) {
element.click();
}

Why do you want to do 10 taps in quick succession ? Is this valid user story at all ?

Till date didn’t come across any app which needs such actions :grinning:

Thanks for your reply, it’s a valid user story for my case, and it would be great if anyone could give me some idea how to do it. THANK YOU!

@yitelu last time i needed similar i used following approach.

  • tap by element IS slow thus use tap by X, Y!
  1. find element
  2. get is center x,y
  3. now tap 10 times using x,y - it is times faster then by element (which involves element search first)

Hi @Aleksei ,
Thanks for your reply. it seems that TouchAction tap is deprecated, wondering if you know other method? or wondering if you could share how to implement it?
THANK YOU

here’s my code attempts:

WebElement webElement = driver.findElement(By.xpath("//android.widget.TextView[@index=‘1’]"));
int startX=webElement.getLocation().getX();
int startY=webElement.getLocation().getY();

 TouchAction action = new TouchAction(driver);

 for(int i=1; i<11; i++){
             action.tap(startX, startY);
 }

@yitelu check -> https://github.com/appium/java-client/blob/master/docs/Touch-actions.md

and look at MultiTouchAction!

1 Like

Awesome! that’s exactly what i needed! thanks

@Aleksei
I also needed to tap on a textView 10 times for a use case and tried both the TouchAction & MultiTouchAction with the below code.

Solution 1: Using TouchAction class

	TouchAction action = new TouchAction(driver);
	int startX=mobEl.getLocation().getX();
	int startY=mobEl.getLocation().getY();
	for(int i=1; i<11; i++){
		action.tap(PointOption.point(startX,startY)).perform();
	}

Solution 2: Using MultiTouchAction class

MultiTouchAction multiTouch = new MultiTouchAction(driver);
int startX=mobEl.getLocation().getX();
int startY=mobEl.getLocation().getY();
	 for (int i = 0; i < 10; i++) {
	     TouchAction tap = new TouchAction(driver);
	     multiTouch.add(tap.press(PointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(400))).release());
	 }

	 multiTouch.perform();

Solution 1 worked for me on Android.

@Aleksei The solution 1 you see above works on my Android but it does not work on iOS.
The script finds elements and taps on it but no feedback from the app. Do you have any idea?

another examples -> http://appium.io/docs/en/commands/interactions/touch/multi-touch-perform/

Try mobile: tapWithNumberOfTaps on iOS: http://appium.io/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures/index.html#mobile-tapWithNumberOfTaps

1 Like

@mykola-mokhnach Thank you so much. Really appreciate it. That worked for me.
@Aleksei Thank you as well for the help.

So here is the complete solution for Android and iOS.

	public void multiTap(AppiumDriver<?> driver, MobileElement mobEl, int numberOfTimes) { //Performs multitap

	if(driver instanceof AndroidDriver){
		TouchAction action = new TouchAction(driver);
		int startX=mobEl.getLocation().getX();
		int startY=mobEl.getLocation().getY();
		for(int i=1; i<=numberOfTimes; i++){
			action.tap(PointOption.point(startX,startY)).perform();
		}
	}else if(driver instanceof IOSDriver) {
		JavascriptExecutor js = (JavascriptExecutor) driver;
		Map<String, Object> params = new HashMap<>();
		params.put("numberOfTaps", numberOfTimes);
		params.put("numberOfTouches",1);
		params.put("element", mobEl.getId());
		js.executeScript("mobile: tapWithNumberOfTaps", params);
	}

}