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!
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.
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.
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:
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(1280, 1013)).perform()
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(1280, 1013)).perform()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With