Driver.tap not working

Hello Everyone,

Im new to Appium and started yesterday. In one of the test case I used driver.tap() with specific cordinate and it worked well. I used the same in another test case and it didn’t work :frowning:

Please help me how to use tap or is there any alternate I can use for tapping.

Try this :

/**

  • Created by sargisazaryan on 7/24/15.
    */
    public class PointOnScreen {
    public double x;
    public double y;

    public PointOnScreen (double x, double y) {
    this.x = x;
    this.y = y;
    }

    public double getX() {
    return this.x;
    }

    public double getY() {
    return this.y;
    }

    public PointOnScreen moveBy(int xOffset, int yOffset) {
    return new PointOnScreen(this.x + xOffset, this.y + yOffset);
    }

    public boolean equals(Object o) {
    if(!(o instanceof PointOnScreen)) {
    return false;
    } else {
    PointOnScreen other = (PointOnScreen)o;
    return other.x == this.x && other.y == this.y;
    }
    }

    public void move(int newX, int newY) {
    this.x = newX;
    this.y = newY;
    }

    public String toString() {
    return String.format("(%e, %e)", new Object[]{Double.valueOf(this.x), Double.valueOf(this.y)});
    }
    }

    public static void tapOnPoint(AndroidDriver driver, final PointOnScreen pointOnScreen) {
    driver.executeScript(“mobile: tap”, new HashMap<String, Double>() {{
    put(“tapCount”, 1.0);
    put(“touchCount”, 1.0);
    put(“duration”, 0.1);
    put(“x”, pointOnScreen.x);
    put(“y”, pointOnScreen.y);
    }});
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }