public void swipeLeft(WebElement element) { // Get the element's dimensions and coordinates int startX = element.getLocation().getX() + (int) (element.getSize().width * 0.8); // 80% from the left int endX = element.getLocation().getX() + (int) (element.getSize().width * 0.2); // 20% from the left int y = element.getLocation().getY() + (element.getSize().height / 2); // Center Y of the element
// Define a PointerInput for gestures PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence swipe = new Sequence(finger, 1);
// Move to start position swipe.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), startX, y));
// Press down swipe.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
// Move to end position swipe.addAction(finger.createPointerMove(Duration.ofMillis(600), PointerInput.Origin.viewport(), endX, y));
// Release swipe.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
// Perform the swipe driver.perform(Arrays.asList(swipe)); }