- I have tried with below method for swipe gestures.
- I need to swipe across photo gallery images both left to right and vice versa.
- I have tried so many solutions, but nothing worked at all.
- I am searching for reliable solution for swipe gestures for iOS app.
- I am using iOS simulator 8.3 version and java as language.
- If any one got swipes successfully in simulator means, please provide an solution.
- Really, I got struck with this swipe gestures, I don't how to proceed. Please help me.
// method 1
WebElement el= driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAElement[1]/UIAScrollView[1]/UIAImage[1]");
String orientation = driver.getOrientation().value();
System.out.println("o="+orientation);undefined> // get the X coordinate of the upper left corner of the element, then add the element's width to get the rightmost X value of the element
int leftX = el.getLocation().getX();
int rightX = leftX + el.getSize().getWidth();
// get the Y coordinate of the upper left corner of the element, then subtract the height to get the lowest Y value of the element
int upperY = el.getLocation().getY();
int lowerY = upperY - el.getSize().getHeight();
int middleY = (upperY - lowerY) / 2;
if (orientation.equals("portrait")) {
// Swipe from just inside the left-middle to just inside the right-middle of the element over 500ms
driver.swipe(leftX + 5, middleY, rightX - 5, middleY, 500);
}
else if (orientation.equals("landscape")) {
// Swipe from just inside the right-middle to just inside the left-middle of the element over 500ms
driver.swipe(rightX - 5, middleY, leftX + 5, middleY, 500);
}
// method 2
TouchAction act = new TouchAction(driver);
WebElement To_elem = driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAElement[1]/UIAScrollView[1]/UIAImage[2]");
WebElement from_elem = driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAElement[1]/UIAScrollView[1]/UIAImage[3]");
act.press(from_elem ).moveTo(To_elem).release().perform();
// method 3
JavascriptExecutor js = (JavascriptExecutor) driver;
Dimension size = driver.manage().window().getSize();
HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();
swipeObject.put("startX", size.getWidth());
swipeObject.put("startY", size.getHeight());
swipeObject.put("endX", size.getWidth()/4);
swipeObject.put("endY", size.getHeight());
swipeObject.put("duration", 2);
js.executeScript("mobile: swipe", swipeObject);
// method 4
TouchAction act = new TouchAction(driver);
act.press(274, 151).moveTo(712, 151).release().perform();
sleep(9000);
// method 5
TouchAction tAction=new TouchAction(driver);
int startx = driver.findElement(By.className("UIACollectionCell")).getLocation().getX();
int starty = driver.findElement(By.className("UIACollectionCell")).getLocation().getY();
int endx = driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell[6]")).getLocation().getX();
int endy = driver.findElement(By.xpath(" //UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell[6]")).getLocation().getY();
System.out.println(startx + " ::::::: " + starty + " ::::::: " + endx + " ::::::: " + endy);
//First tap on the screen and swipe it right using moveTo function
tAction.press(startx+20,starty+20).moveTo(endx+20,endy+20).release().perform();
//Second tap on the screen and swipe it left using moveTo function
tAction.press(endx+20,endy+20).moveTo(startx+20,starty+20).release().perform();