Tap action with X and Y coordinates for perform on element Interaction

You are here:
< All Topics

Overview:

In Appium, you can perform a tap action using coordinates (X and Y) with a method similar to the TouchAction class. This approach is especially useful when:

  • The element you want to interact with isn’t uniquely identifiable.
  • The element is partially hidden or out of view.

In such cases, you can directly tap on a specific area by providing coordinates. These coordinates can also be calculated as a percentage of the screen size to dynamically determine the X and Y positions. Once calculated, the tap action is executed at the specified location.

Why Use Coordinate-Based Tap?
  • To bypass issues with non-unique elements.
  • To interact with app areas when standard element locators don’t work.
Steps to Perform:
  1. Calculate the X and Y coordinates (or percentage-based values).
  2. Use the tap action keyword or method to execute the gesture.

This method ensures that the action is performed precisely on the required area, regardless of element accessibility issues.

 

Note: The tap action keywords for X and Y coordinates are specifically designed for Android and iOS devices. They use platform-specific touch gestures supported by frameworks like Appium. These keywords work accurately by considering the screen resolution, making them adaptable to different device sizes. This ensures precise interactions and effective automation for mobile applications, regardless of screen dimensions.

 

Step-by-Step Guide to Identify X and Y Coordinates:
  1. Visit the Tool:
    Open this link: Mouse Coordinates Tool.
  2. Navigate to Step 5:
    Scroll to step number 5 on the webpage, where you’ll find an option to upload an image.
  3. Upload Your Screenshot:
    • Choose a screenshot that contains the element for which you want to find the X and Y coordinates.
    • Ensure the file meets the size requirements mentioned on the page.
    • Click the “Upload Image” button.
  4. Select the Element:
    • Once the image is uploaded and displayed on the screen, click on the element in the image.
    • The tool will show the exact X and Y coordinates of the selected area.

This method helps you easily identify coordinates for accurate interactions during automation.

 

 

 

Step 2: Retrieve and Customize Coordinates

  1. Get the Coordinates:
    • Click on the element in the uploaded image for which you want to find the coordinates.
    • Scroll down to view the Recorded Coordinates section below the image.
  2. Customize as Needed:
    • You can adjust the recorded coordinates to match your specific requirements.

This flexibility allows you to fine-tune the coordinates for precise and effective automation.

 

 

 

Step 3: How to calculate the coordinates.
  • For X coordinates:

                   Xcoordinate=(Xvalue/image width)×100

  • For Y coordinates:

                  Ycoordinate=(Yvalue/image height)×100

This will give you the X and Y coordinates as a percentage of the image width and height.

 

  • Once you obtain the X and Y coordinate values, write the syntax as follows and use it in your test case :  50%WIDTH,50%HEIGHT

 

 

 

 

Happy Testing!!

Table of Contents