I want to know how to click with coordinates in Appium Java, I want to click on an element by (x,y) as this element is the send button on the keyboard. and it doesn't have a locator
how to click with cordinates in appium java?
96 Views Asked by ahmed mahmoud At
3
There are 3 best solutions below
0
On
To click on some coordinates:
TouchAction touchAction = new TouchAction(driver);
int xPoint = 100;
int yPoint = 200;
touchAction.tap(PointOption.point(xPoint , yPoint)).perform();
0
On
I was facing the same issue because TouchAction is Deprecated. Then i found
public static void tap(AppiumDriver driver, int x, int y) {
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence sequence = new Sequence(finger, 1)
.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), x, y))
.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
.addAction(new Pause(finger, Duration.ofMillis(150)))
.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Collections.singletonList(sequence));
System.out.println("Tap with Coordinates");
}
Calling the method: tap(driver, 200, 200);
this will tap on the coordinates x=200 & y=200
You can try this:
TouchAction touchAction=new TouchAction(driver);
touchAction.tap(xPoint, yPoint).perform();