Reputation: 41
I am trying to swipe left on a particular element on iOS 10 using Appium 1.6 to expose the delete button.
Touch Action and Swipe code for swiping left direction is working fine for appium 1.4 but the issue emerged only after we migrated to appium 1.6.
Any help is greatly Appreciated
Upvotes: 1
Views: 2196
Reputation: 219
Try this code. Call flick_left and pass the WebElement.
flick_left(element)
public void flick_left(WebElement flick_element) {
Point location = flick_element.getLocation();
Dimension size = flick_element.getSize();
int flick_x, flick_y, flick_start_x, flick_end_x,flick_start_y,flick_end_y;
flick_x =size.getWidth();
flick_y = location.y + (size.getHeight()/2);
flick_start_x = flick_x - (int)((double)flick_x*0.25);
flick_end_x = flick_x -(int)((double)flick_x*0.55);
swipe(flick_start_x, flick_y, flick_end_x, flick_y,-200);
}
public void swipe(int swipe_start_x, int swipe_start_y, int swipe_end_x, int swipe_end_y,int duration){
int x = swipe_start_x;
int y = swipe_start_y;
int x_travel = swipe_end_x-swipe_start_x;
int y_travel = swipe_end_y-swipe_start_y;
TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(duration).moveTo(x_travel, y_travel).release();
action1.perform();
}
Upvotes: 0
Reputation: 128
public void swipe(String direction, int offset, int time) {
int y = appiumDriver.manage().window().getSize().getHeight();
int x = appiumDriver.manage().window().getSize().getWidth();
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(x+" "+y);
System.out.println("Entering swipe");
if("right".equalsIgnoreCase(direction))
{
System.out.println("Swipe Right");
touchAction.press(x-offset, y/2).moveTo(-(x-(2*offset)), 0).release().perform();
}else if("left".equalsIgnoreCase(direction)){
System.out.println("Swipe Left");
touchAction.press(offset, y/2).moveTo((x-(2*offset)), 0).release().perform();
}else if("up".equalsIgnoreCase(direction)){
System.out.println("Swipe Up");
touchAction.press(x/2, offset).moveTo(0, y-(2*offset)).release().perform();
}else if("down".equalsIgnoreCase(direction)){
System.out.println("Swipe Down");
touchAction.press(x/2, y-offset).moveTo(0, -(y-(2*offset))).release().perform();
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 219
I had the same issue and now I found the solution.
Details:
Appium 1.6.4 beta
Java-Client-5.x beta
Appium 1.6.x - Swipe has been removed and we have to create own TouchAction for swipe, in that waitAction() use negative value will perform the fast swipe action. e.g waitAction(-200).
TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(-200).moveTo(x_travel, y_travel).release();
action1.perform();
Post your feedback.
Upvotes: 3