Tap by Coordinates
The Tap by Coordinates action performs a single tap at the specified screen coordinates. Unlike the Click Element action, this method does not search for a UI element. It simply taps the specified screen location.
When to Use
Use this action when:
- Interacting with custom UI controls.
- Clicking map locations.
- Selecting graphical objects.
- Tapping image-based buttons.
- Working with applications that do not expose Accessibility information.
Syntax
var task = suremdmjs.automate().clickCoordinates(
<X Coordinate>,
<Y Coordinate>
);
suremdmjs.automate().performAction(
task,
"onSuccess",
"onFailure"
);
Parameters
| Parameter | Required | Description |
|---|---|---|
| X Coordinate | Yes | Horizontal screen coordinate in pixels. |
| Y Coordinate | Yes | Vertical screen coordinate in pixels. |
Parameter Details
X Coordinate
Specifies the horizontal position where the tap should occur.
Example:
540
Y Coordinate
Specifies the vertical position where the tap should occur.
Example:
1200
Example
The following example taps the centre of the device screen.
!#suremdmjs
tapScreen();
function tapScreen() {
var task = suremdmjs.automate().clickCoordinates(540,1200);
suremdmjs.automate().performAction(
task,
"tapCompleted",
"tapFailed"
);
}
function tapCompleted() {
suremdmjs.log("Screen tapped successfully.");
}
function tapFailed() {
suremdmjs.log("Unable to perform tap.");
}
How This Example Works
- Creates a Tap by Coordinates task.
- Specifies the X and Y coordinates.
- Performs a tap at the specified location.
- Executes the success callback after the tap completes.
Expected Result
A single tap is performed at the specified screen coordinates.