I tend to think of swiping in terms of swiping a given element in a specified direction rather than specific coordinates on the screen, so I came up with this helper method in case it's useful for anyone else:
/**
* Swipes an element a specified offset distance
* X/Y Coordinates: distance in number of pixels, values < 1 specify relative screen offset distance
* (example: .75 swipes 75 percent of the width of screen)
* @param elementDef - By object defining the element
* @param touchCount - amount of fingers in touch
* @param xDistance - positive:right, negative:left
* @param yDistance - positive:up, negative:down,
* @param duration - amount of seconds to swipe for
*/
public void swipeElement(WebElement element, double touchCount, double xDistance, double yDistance, double duration) {
// get location of element
Point coords = element.getLocation();
double startX = coords.x;
double startY = coords.y;
// get window size
Dimension size = driver.manage().window().getSize();
//calculate end distance
double endX;
double endY;
//if the distance is a decimal value < 1, it's a relative screen distance
if (Math.abs(xDistance) < 1) {
endX = startX + (size.width * Math.abs(xDistance));
}
else {
endX = startX + xDistance;
}
if (Math.abs(yDistance) < 1) {
endY = startY - (size.width * Math.abs(yDistance));
}
else {
endY = startY - yDistance;
}
Point endCoords = new Point((int)endX, (int)endY);
util.log("Swiping from: " + coords + " To: " + endCoords);
//set up arguments to mobile: swipe
HashMap<String, Double> flickObject = new HashMap<String, Double>();
flickObject.put("touchCount", touchCount);
flickObject.put("startX", startX);
flickObject.put("startY", startY);
flickObject.put("endX", endX);
flickObject.put("endY", endY);
flickObject.put("duration", duration);
driver.executeScript("mobile: swipe", flickObject);
}