5

Any idea how to do this for android? I can't seem to create a method that actually clicks.

I know you can do it with onview, but I just want an x/y position.

Pulkit
  • 119
  • 1
  • 1
  • 6
  • Possible duplicate of [Click by bounds / coordinates](http://stackoverflow.com/questions/22177590/click-by-bounds-coordinates) – Jacob Holloway Mar 13 '17 at 22:50

1 Answers1

8

The answer is already given here.

public static ViewAction clickXY(final int x, final int y){
    return new GeneralClickAction(
        Tap.SINGLE,
        new CoordinatesProvider() {
            @Override
            public float[] calculateCoordinates(View view) {

               final int[] screenPos = new int[2];
               view.getLocationOnScreen(screenPos);

               final float screenX = screenPos[0] + x;
               final float screenY = screenPos[1] + y;
               float[] coordinates = {screenX, screenY};

               return coordinates;
            }
        },
        Press.FINGER);
}
Community
  • 1
  • 1
JeKa
  • 580
  • 5
  • 11