If I want to tap on a certain iOS button, should I get a WebElement object from its xpath and invoke the click() method on it, or should I use driver.tap() method to tap a specific x/y coordinate?
According to my understanding, it is better to use driver.tap() method as it is more closely binded to the mobile scenario. tap() method belongs to AppiumDriver class while the click() method belongs to the WebDriver class.
It’s better to go for tap() method as they have extracted all mobile native gestures and pushed them to java_client library for better implementation.
By the way, you can also use driver.tap(int x, WebElement we, int y) if you don’t want to go by specific x/y coordinates.
How we can pass x/y coordinates of an element? How we can get that?
Currently, I’m using click() function in my tests which needs only element to click with no coordinates.
I’m new to appium and don’t know how to pass coordinates in tap() function. Please explain me with example.
You can get the x/y coordinates of the element through the inspector provided by appium UI tool.
For general, the tap function is tap(int x, WebElement we, int y). Here, you can pass 1 as x and y and the WebElement object. This would perform a tap on the webElement you are trying to click.
Yes I agree with you. But if we do not have any way to identify element and we have only coordinates then we have to use TAP? Because I think wan no specify coordinate with Click () method.
tap and click sometimes suffer from the elements not being valid anymore and returning “not able to tap element”.
With this being said, I normally use tab on buttons that I’m sure are there. Whenever I get any problem with tapping on visible elements (but appium states they aren’t visible, etc.) I user TouchAction.new.press on Element. So no maintenance costs and it always presses on the spot even when tap/click does not work
I am using like this new TouchAction(((MobileDriver)driver).tap(arg0, arg1, arg2)), and here I am not getting tap() method which takes only one arguement, also perform() method is not coming.
Could you please explain your method in more detail.
public static WebDriver getDriver(){
return AppiumTest.driver;
}
It returns the driver, to make actions afterward.
Then each screen of the app is split in two sides : first I get the elements, then I create the methods (actions).
To get the elements, I use the method findElement i’ve wrote above.
And after, to tap on an element, I’ve created the method tapOn wrote above too. But getDriver() and tapOn() is wrote in another class accessible for each test.
Hello,
I have a query regarding tap function. I wanted to test a touch action on the object that we have created on the canvas . I tried using tap and click but it didn’t work me. And I am not able to see the object that I wanted to touch using ui automator. The object was a rectangle created by the 4 lines . Can someone suggest me how to perform touch on this object .