Swiping with Android

Hi Guys

I just upgraded from java client 5.0.0-BETA9 to 5.0.4 which subsequently meant that I had to update the swipe methods and now I’m having issues with the TouchAction method thats replaced driver.swipe().

On Beta9 I used this to swipe on Android which worked great:

   Point center = getCenter(element);

  driver.swipe(center.getX(), center.getY(), center.getX(), center.getY()-100, duration);

On 5.0.4 I’m using the new TouchAction method but it keeps giving me this error: “The coordinates provided to an interactions operation are invalid.”

Point center = getCenter(element);

new TouchAction(driver).press(center.getX(),center.getY()).moveTo(center.getX(), center.getY() - 100).perform().release();

No matter what I try it always returns “The coordinates provided to an interactions operation are invalid.”.

Anybody have any clues what I’m doing wrong?

Thanks

1 Like

move to coordinates are relative and not absolute. There are several issues opened lately about TouchAction due to swipe function removal, so just search in forum and “play” with answers.

Thanks

Ola Telmo

Thanks for the reply, it seems there’s some issues around TouchAction for swiping so for now I’m actually going to degrade back to BETA9 until they fix TouchActions in a later release.

Thanks

I don’t have any issues with TouchAction. What is the problem you are having after trying relative coordinates?

Ola Telmo

So if I want to swipe up by a 100 pixels from an element how would I do it? It seems like TouchAction won’t take a negative number.

new TouchAction(driver).press(center.getX(),center.getY()).moveTo(center.getX(), center.getY() - 100).perform().release();

You are in iPhone?

Use relative coordinates on move to, like this:

new TouchAction(driver).press(center.getX(),center.getY()).moveTo(0,  - 100).perform().release();
1 Like

How do i get relative coordinates?

Already answered you in other post , but in general , try to use drive.location , size , dimensions , etc… and calculate your needs

good luck

1 Like

Found even easier way:
The Uiautomatorviewer provides you with the relative coordinates you need, just take a snapshot of the phone and place the mouse on the point you want to get the coordinates :slight_smile:

Hi @lina,

My advice is to make functions that when you want to swipe without any element references, it receives percentage and you calculate the proper coordinates, that way it will work on any device and not just on the one you are using now.

Something like (with percentage between 0 and 1):

Dimension size = driver.manage().window().getSize();
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
1 Like

As it was already mentioned , it’s better not to use “fixed” values but relative one.