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.”.
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 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.
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
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);