Performing touch action using co ordinates

iam trying to tap on an element using pointoption and it is not working
iam using the latest verison of Appium v1.10.0
below is the code in the page object

TouchAction t =new TouchAction(driver);
PointOption point=new PointOption();
public void scroll_to_orders()
{

   new TouchAction(driver).tap(PointOption.point(299,437)).release().perform(); 
}

below is the import file
import io.appium.java_client.touch.offset.PointOption;

Need help on this

make sure you have the latest java client.
A better approach would be to get the center the element and tap on it

org.openqa.selenium.Point centerOfElement = element.getCenter();
new TouchAction<>(driver).tap(point(centerOfElement.x, centerOfElement.y)).perform();

Why don’t you tap directly on the element?
public void tap(MobileElement yourElement) {
new TouchAction<>(driver).tap(tapOptions().withElement(element(yourElement))).perform();
}

how to get the center of the element ?
iam using UIAUTOMATOR to find the co ordinates

org.openqa.selenium.Point centerOfElement = element.getCenter();
new TouchAction<>(driver).tap(point(centerOfElement.x, centerOfElement.y)).perform();

will the above syntax work? bcse i can see the import file and the element combined , iam new to appium. plse can u explain me and help me?
org.openqa.selenium.Point centerOfElement

Try this
public void pressByCoordinates (int x, int y, long seconds) {
new TouchAction(driver)
.press(point(x,y))
.waitAction(waitOptions(ofSeconds(seconds)))
.release()
.perform();
}

Aish

i tried the above coder and got the error.
I need to put the code in PageObject
can you plse help

import
import static io.appium.java_client.touch.offset.PointOption.point;
error should be removed.

hi Aish

i tried what you gave and it is not clicking the co ordinates

POM code
public void scroll_to_orders(int x, int y, long seconds)
{
((AndroidDriver)driver).findElementByAndroidUIAutomator(“new UiScrollable(new UiSelector()).scrollIntoView(text(“Orders”));”);
// t.tap(new PointOption().withCoordinates(359, 485)).perform();
new TouchAction(driver).press(point(299,437)).waitAction(waitOptions(ofSeconds(seconds))).release().perform();
// new TouchAction(driver).tap(PointOption.point(299,437)).release().perform();
}

test case

@Test
public void c_orders()
{
object = new PageObjects(driver);
object.scroll_to_orders(299, 437,10);

}

Can you help

hi Aish
any update plse

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(299, 437)).perform()

This should work, i tried it myself and i am able to click using coordinates.

1 Like

hi Aish

thanks for the reply
The above code is also not working for me
Below are the credential details.
I have attached the apk , the PageObject and the test case class in the below link for the kind reference.
https://drive.google.com/drive/folders/1mKEAi0YzVERsFNUcT-wyFGoEtT1cuNiB?usp=sharing
All the credentials as well

in my PageObject code i have swiped and tried to click using co ordinates in the scroll_to_orders() method

Let me explain the requirement fully
1: launch the app
2: after launching click on the “skip the tour”
3 : Click on internal user
4 ; enter the credentials
5 : click the sync button on the top right
6 : after the sync we can see list page
7 : scroll to orders
8 : click orders

The problem here is in the list page after synce we don’t have name, id and any other attributes , we have only common class name.
Need to click on orders
can you plse help

Hi Aish

any update on the above plse

Hi Aish
Any update plse

can you tell us the versions you are using for :

org.seleniumhq.selenium
io.appium ?

added the dependancies below

org.seleniumhq.selenium
selenium-java
3.141.59

io.appium java-client **6.1.0**

Appium desktop version v1.10.0

I hope below code works for you

TouchAction action = new TouchAction(driver);
action.press(PointOption.point(x,y)).release().perform();

This is working on our end on android.

Config i am using

org.seleniumhq.selenium
selenium-java
3.141.59
io.appium java-client 7.0.0
Appium : 1.9.1 (terminal version)

1 Like

Wonderful!!! Thanks a lot man!!