25
Mar

SwipeUp on mobile element in selenium

Swipe UP on the Element

public void swipeUPOnElement(WebElement element) {
Point point = element.getLocation();
Dimension eleSize = element.getSize();
int centerX = point.getX() + (eleSize.getWidth() / 2);
int centerY = point.getY() + (eleSize.getHeight() / 2);
int moveToX = point.getX() + (eleSize.getWidth() / 2);
int moveToY = point.getY();

new TouchAction(driver)
.press(PointOption.point(centerX,centerY))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo(PointOption.point(moveToX, moveToY))
.release().perform();
}