Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium tap(int x, int y) function seems to be deprecated. Any replacements?

Tags:

java

appium

I'm trying to automate an Android game and for that I'm using X,Y co-ordinates to make a button click, as identifying elements through ID, Xpath etc. is not possible for games. I'm using TouchAction tap(int x, int y) method (Appium Method) for achieving this. But unfortunately this method tap(int x, int y) seems to be deprecated. The other options replacing this looks to be --> touchAction.tap(PointOptions tapOptions) and touchAction.tap(TapOptions tapOptions). The same is the case with touchAction.press as well.

My code to touch a specific button looks like this:

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(1280, 1013).perform();

Here, the X,Y values are found using Touch points in Android Device [Developer Options > Show pointer location]

Can anyone suggest a better way to achieve the same using non deprecated method? Thanks!

like image 631
Sandeep Harisankar Avatar asked Mar 01 '18 11:03

Sandeep Harisankar


People also ask

What is the difference between tap and click in appium?

tap() method belongs to AppiumDriver class while the click() method belongs to the WebDriver class. It's better to go for tap() method as they have extracted all mobile native gestures and pushed them to java_client library for better implementation.

How do you find the X and Y coordinates of an element in appium?

1 Answer. Show activity on this post. You don't need any tools for getting the x, y values. After enabling this once you tap on screen -> x, y locator values will be displayed in top bar.


1 Answers

You can view the TouchAction documentation here:

https://appium.github.io/java-client/io/appium/java_client/TouchAction.html

Here's the method that replaced the tap() you are using:

https://appium.github.io/java-client/io/appium/java_client/TouchAction.html#tap-io.appium.java_client.touch.offset.PointOption-

and here is the PointOption documentation, which is the new parameter to use with tap():

https://appium.github.io/java-client/io/appium/java_client/touch/offset/PointOption.html

So to answer your question, you have two choices with PointOption:

  1. Using PointOption.point(x, y), which is a static instance of PointOption with those coordinate values

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(1280, 1013)).perform()
  1. Using PointOption().withCoordinates(x, y), which returns a reference to the PointOption instance after setting those coordinate values

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(1280, 1013)).perform()
like image 105
Taryn Avatar answered Oct 18 '22 20:10

Taryn