Difference between click() and tap()

You can use x-y coordinates if you know them to tap that region of the screen

Hello ,

Thanks for the reply .I know the coordinates but either of the tap function or long press function is not able to perform the touch on the canvas.

Thanks
Jaswitha

is this app a hybrid app or native app? if your app is a hybrid then you not be able to inspect element using UI automator you can try use chrome remote debugger.

Thanks .It is a native app.I will try chrome remote bugger .The main problem is with touching the object even though i have exact coordinates. I can actually see that it is performing touch by enabling show touches settings option in my tablet .Besides i am not able to see the window that has to be opened after touch is performed.

on the green card i need to tap.But it is not performing touch on this card.Can anyone help me with this.

One quick question about the coordinates. Is it correct that when you dump the View Hierarchy from the DDMS and then click on the specific element you get the coordinates?

Hi Osamaa

you can get element co-ordinates from the WebElement itself.
Try the below code :
WebElement ele = driver.findElement(By.className(“abc”));
Point loc = ele.getLocation();
int x = loc.getX();
int y = loc.getY();
driver.tap(x, ele, y);

Hope this will help :slight_smile:

2 Likes

your solution worked for me. Thanks

1 Like

This is what worked for me.

As Appium java-client works directly with mobile native gestures.

Hi, i used your solution but it marked red underline below word “tap”

you taking left upper corner! which is wrong. change it to:

MobileElement ele = (MobileElement) driver.findElement(By.className("abc"));
Point loc = ele.getCenter(); // gives NPE if element NOT exists

regarding tap use:

  1. best: http://appium.io/docs/en/commands/interactions/actions/
  2. http://appium.io/docs/en/commands/interactions/touch/tap/
PointOption pointOption = new PointOption().withCoordinates(loc.x, loc.y);
new TouchAction(driver).tap(pointOption).perform();
  1. there also other ways …

Thanks for reply, but now getting red mark below “MobileElement”

This is appium element. What appium java client you use? MobileElement should be even in very old.

im using java-client-8.0.0-beta

I am still with old. With new client you can use old WebElement

When i changed to WebElement, there is no error in script but got this error in console

@Innaya pls read doc migration sent by mykola-mokhnach
->

The changes made in Selenium 4 broke class name selector strategy in Appium. AppiumBy.className should be used instead of Selenium's By.className now.