How to double tap on an element in appium java for android


#1

How to double tap on an element in appium java for android. I’m working on Maven project.
I have found some solution but its not working at all.


#2

Hi,

I just tried this and it worked:

new TouchAction(driver).press(300,550).release().perform().press(300,550).release().perform()

#3

@Telmo_Cardoso for me it is working as action itself BUT it gives error. In Appium logs i see next tap goes to double coordinates :slight_smile: = outside mine screen

Thus for me it is working old way as:

new TouchAction((MobileDriver) driver).press(x,y).waitAction(Duration.ofMillis(50)).release().perform();
new TouchAction((MobileDriver) driver).press(x,y).waitAction(Duration.ofMillis(50)).release().perform();
   doubleTapElement(): x - 314, y - 1875
2017-05-18 09:21:34:971 - [HTTP] --> POST /wd/hub/session/d1bba020-175d-473f-a6f4-ee5ece6f1371/touch/perform {"actions":[{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}}]}
2017-05-18 09:21:34:971 - [debug] [MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}}],"d1bba020-175d-473f-a6f4-ee5ece6f1371"]
2017-05-18 09:21:34:977 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":314,"y":1875}}
2017-05-18 09:21:34:980 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":314,"y":1875}}
2017-05-18 09:21:34:981 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-05-18 09:21:34:982 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
2017-05-18 09:21:34:996 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]
2017-05-18 09:21:34:997 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchDown using element? false x: 314, y: 1875
2017-05-18 09:21:35:025 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
2017-05-18 09:21:35:026 - [debug] [AndroidBootstrap] Received command result from bootstrap
2017-05-18 09:21:35:084 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchUp","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:089 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchUp","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:089 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-05-18 09:21:35:089 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchUp
2017-05-18 09:21:35:091 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]
2017-05-18 09:21:35:092 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchUp using element? false x: 314, y: 1875
2017-05-18 09:21:35:127 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
2017-05-18 09:21:35:129 - [debug] [AndroidBootstrap] Received command result from bootstrap
2017-05-18 09:21:35:130 - [debug] [MJSONWP] Responding to client with driver.performTouch() result: null
2017-05-18 09:21:35:130 - [HTTP] <-- POST /wd/hub/session/d1bba020-175d-473f-a6f4-ee5ece6f1371/touch/perform 200 159 ms - 76 
2017-05-18 09:21:35:134 - [HTTP] --> POST /wd/hub/session/d1bba020-175d-473f-a6f4-ee5ece6f1371/touch/perform {"actions":[{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}},{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}}]}
2017-05-18 09:21:35:134 - [debug] [MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}},{"action":"press","options":{"x":314,"y":1875}},{"action":"wait","options":{"ms":50}},{"action":"release","options":{}}],"d1bba020-175d-473f-a6f4-ee5ece6f1371"]
2017-05-18 09:21:35:136 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:142 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:142 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-05-18 09:21:35:142 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
2017-05-18 09:21:35:145 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]
2017-05-18 09:21:35:147 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchDown using element? false x: 314, y: 1875
2017-05-18 09:21:35:160 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
2017-05-18 09:21:35:161 - [debug] [AndroidBootstrap] Received command result from bootstrap
2017-05-18 09:21:35:216 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchUp","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:220 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchUp","params":{"x":314,"y":1875}}
2017-05-18 09:21:35:220 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-05-18 09:21:35:220 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchUp
2017-05-18 09:21:35:224 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]
2017-05-18 09:21:35:224 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchUp using element? false x: 314, y: 1875
2017-05-18 09:21:35:255 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
2017-05-18 09:21:35:256 - [debug] [AndroidBootstrap] Received command result from bootstrap
2017-05-18 09:21:35:256 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":628,"y":3750}}
2017-05-18 09:21:35:260 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":628,"y":3750}}
2017-05-18 09:21:35:260 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-05-18 09:21:35:261 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
2017-05-18 09:21:35:264 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]
2017-05-18 09:21:35:264 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":29,"value":"Coordinate [x=628.0, y=3750.0] is outside of element rect: [0,0][1440,2392]"}

#4

Hi,

yes. I see it appeared an error in logs also :slight_smile: but it worked. Doing two separated actions for me it taps twice, but it is not quick enough to be considered double tap.

Also quickly tried multitouch, but it didnt’ work, and I just dont have time to explore it further, but I encourage @Al_Imran to try several alternatives.


#5

you can also use driver.tap() method as well for tapping two time.


#6

Thanks a lot @Telmo_Cardoso, It’s working cool :slight_smile:


#7

You can try @Telmo_Cardoso’s solution, It’s working fine. Thanks


#8

This worked for me.

new TouchAction(driver).press(100,300).release().perform().waitAction(Duration.ofMillis(100)).press(100,300).release().perform();


#9

None of the above solution is working for me for android! All of them are serving double click/tap with consecutive manner which are basically two single clicks/taps.

new TouchAction(driver).doubleTap(ElementOption.element(doubleTap)).release().perform();

Is this applicable for iOS only? Given at http://appium.io/docs/en/commands/interactions/touch/double-tap/

I am using this dependency

<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>

#10

Now in the latest version of Appium that is 6.1.0 things has changed for mobile actions. To work on mobile actions there is a class AndroidTouchAction/ IOSTouchAction.
Below is the code for some actions:

//Tap
AndroidTouchAction touch = new AndroidTouchAction(driver);
touch.tap(ElementOption.element(element)).perform();

//Press
AndroidTouchAction touch = new AndroidTouchAction(driver);
touch.press(ElementOption.element(element)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(3))).release().perform();

//Long Press
AndroidTouchAction touch = new AndroidTouchAction(driver);
touch.longPress(ElementOption.element(element)).release().perform();

//Swipe
AndroidTouchAction touch = new AndroidTouchAction(driver);
touch.longPress(ElementOption.element(driver.findElementByXPath("//[@content-desc=‘15’]"))).moveTo(ElementOption.element(driver.findElementByXPath("//[@content-desc=‘45’]"))).release().perform();

//Scroll
driver.findElementsByAndroidUIAutomator(“new UiScrollable(new UiSelector()).scrollIntoView(text(“yourText”));”);

//Drag and drop
AndroidTouchAction touch = new AndroidTouchAction(driver);
touch.longPress(ElementOption.element(element)).moveTo(ElementOption.element()).release().perform();

Hope this will help :slight_smile:

Thanks,
Prasidh


#11

//Double Tap On Element
new TouchAction(androiddriver).press(PointOption.point(element.getLocation().getX(),element.getLocation().getY())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform();
new TouchAction(androiddriver).press(PointOption.point(element.getLocation().getX(),element.getLocation().getY())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform();

//Double Tap By Screen
org.openqa.selenium.Dimension size = androiddriver.manage().window().getSize();
// calculate coordinates for vertical swipe
int startVerticalY = (int) (size.height * 0.8);
int endVerticalY = (int) (size.height * 0.21);
int startVerticalX = (int) (size.width / 2.1);
new TouchAction(androiddriver).press(PointOption.point(startVerticalX,startVerticalY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform();
new TouchAction(androiddriver).press(PointOption.point(startVerticalX,startVerticalY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform();


#12

@Telmo_Cardoso Worked for me too.Thanks!