Vertical swipe to a particular element on page in iOS device is not working with Appium 1.10


#1

Vertical swipe to a particular element on page in iOS device is not working with Appium 1.10.

Tried on iOS versions 9, 10, 11 on different iPhones but still not working.

We have tried the below code for vertical swipe but it is not working:

((IOSDriver<WebElement>) webDriver).swipe(

webDriver.manage().window().getSize().width / 2,

webDriver.manage().window().getSize().height * 7 / 12,

webDriver.manage().window().getSize().width / 2,

webDriver.manage().window().getSize().height / 2, 0);

Below code worked only to scroll down to the bottom of the page but not to the particular element.

JavascriptExecutor js = (JavascriptExecutor) webDriver;

HashMap<String, String> scrollObject = new HashMap<String, String>();

scrollObject.put(“direction”, “down”);

js.executeScript(“mobile: scroll”, scrollObject);

After that we have used the Touch Action class to swipe down but still not working:

Dimension size = driver.manage().window().getSize();

int endPoint = (int) (size.width * 0.20);

int startPoint = (int) (size.width * 0.80);

int anchor = size.height/2;

new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofSeconds(0)).moveTo(anchor, endPoint).release().perform();


#2

let try, i hope it can help you:

public void swipeElementByPercentage(IOSElement element, Direction direction, double endXPercen) {

int startX, startY, endX, endY;

int screenWidth = driver.manage().window().getSize().width;
int screenHeight = driver.manage().window().getSize().height;

switch (direction) {
case TOP:
startX = element.getCenter().getX();
startY = element.getSize().getHeight();

endX = startX;
endY = screenHeight - (int) (screenHeight * endXPercen);
break;
case RIGHT:
startX = element.getLocation().getX();
startY = element.getLocation().getY();

endX = (int) (screenWidth * endXPercen);
endY = startY;
break;
case LEFT:
startX = element.getSize().getWidth();
startY = element.getCenter().getY();

endX = screenWidth - (int) (screenWidth * endXPercen);
endY = startY;
break;

default:
startX = element.getCenter().getX();
startY = element.getLocation().getY();

endX = startX;
endY = (int) (screenHeight * endXPercen);
break;
}

Point startPoint = new Point(startX, startY);
PointOption startPointOption = new PointOption().withCoordinates(startPoint);

Point endPoint = new Point(endX, endY);
PointOption endPointOption = new PointOption().withCoordinates(endPoint);

WaitOptions waitOptions = new WaitOptions().withDuration(Duration.ofMillis(200));

touchAction().press(startPointOption).waitAction(waitOptions).moveTo(endPointOption).waitAction().release().perform();

}

then use it:

actions.swipeElementByPercentage(element , Direction.TOP, 0.9);