Swipe broken on 1.3.3? ios 8.1

very strange,
no swipe in my Simulator when using simulator…
I give up, will hope it will work on future versions…

hi @menypeled,

I have the same issue as yours: the swipe action works fine on real device but on simulator it doesn’t work. I have tried with many Appium versions and still got no luck.

My latest stack is: Appium 1.3.4, java client 2.1.0, xcode 6 and ios 8.1

My current workaround is to use AppleScript to calculate the coordinate of the simulator window, then move the cursor to the center of that window and drag from there. I hate this solution because I have to create another thread to do that and of course it cannot run on a remote hub ( like SauceLab) but it’s the only way that works for me.

I really hope that we can find a better solution for this

Thanks tbao,
If you can send me code sample that will show how to use the AppleScript it will be most appreciated.
Thanks again…

@menypeled, Here is the java function to get the center coordinate of the simulator:

private static Point getCenterCoordinateOfIosSimulator()
throws ScriptException {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName(“AppleScript”);

    // Force the simulator's window to be in front of others
    String script = "tell application \"iOS Simulator\" \n activate \n end tell";
    engine.eval(script);
    // Get simulator's position
    script = "tell application \"System Events\" to tell application process \"iOS Simulator\" \n get position of window 1 \n end tell";
    @SuppressWarnings("unchecked")
    List<Long> simulatorPosition = (List<Long>) engine.eval(script);
    // Get simulator's size
    script = "tell application \"System Events\" to tell application process \"iOS Simulator\" \n get size of window 1 \n end tell";
    @SuppressWarnings("unchecked")
    List<Long> simulatorSize = (List<Long>) engine.eval(script);
    // Calculate center
    int x = simulatorPosition.get(0).intValue()
            + simulatorSize.get(0).intValue() / 2;
    int y = simulatorPosition.get(1).intValue()
            + simulatorSize.get(1).intValue() / 2;
    return new Point(x, y);
}

After you have the center’s coordinate, you can use java.awt.Robot to move the mouse to that position, and then move it up or down accordingly as:

Point point = getCenterCoordinateOfIosSimulator();
Robot robot = new Robot();
robot.mouseMove(point.getX(), point.getY() + offsetFromCentre);
Thread.sleep(200);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep(200);
robot.mouseMove(point.getX(), point.getY());
Thread.sleep(200);
robot.mouseMove(point.getX(), point.getY() - offsetFromCentre);
Thread.sleep(200);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

guys, both swipe and Touchaction work for me.
Appium 1.3.1 or 1.3.3. java-client 2.1.0. iPhone 5S, iOS 7.1 or 8.1

@fangmobile, I don’t know how you can manage to make swipe gesture work on simulator, but according to the last comment on this thread: iOS 8 swipe / scrollTo it seems like we can’t make it and I can confirm it with my observation so far

Thanks.

Appium 1.3.3, java-client 2.0.0, Simulator with iPhone 6, iOS 8.1 - swipe does not work
Appium 1.3.3, java-client 2.0.0, Simulator with iPhone 5, iOS 8.1 - swipe does work.

I did perform just driver.swipe(100, 400, 0, 50, 500).
Additionally I notice:

  1. if delta on coordinates less then 320 pixels, swipe does not work.
  2. swipe does not work for duration < 500 ms.

Hope my finding help someone…

1 Like

Interesting, thanks for posting! I’ll try with your suggestion and see if it works. I really don’t like my workaround to use AppleScript now

swipe still dosent work for me i tried all the above methods
:-1:(

Using ios7-real device

I just updated from appium 1.3.1 to appium 1.3.4 and now execute_script: ‘mobile: swipe’ doesn’t work, because it was deprecated I guess.

But TouchActions swipe only works with x, y and not with elements. Even doing press(element).move_to(.... it doesn’t work, just says "private method 'select' called for...."

Any idea on how to perform basic swipe on elements now?

ok, so apparently the swipe in documentation http://www.rubydoc.info/github/appium/ruby_lib/Appium/TouchAction#swipe-instance_method is wrong

Instead of

swipe(start_x, start_y, end_x, end_y, duration)

should be

swipe(start_x, start_y, height, width, duration)

because it is adding the last two coordinates to the first ones (at least to me).

So I did a quick method for simple swipe with elements where I get the location.y, location x, size.height, size.width of the element and work with that. Not perfect :expressionless: but if there are any native support it will have to do.

This is an example of what I have found to work in Ruby with 1.33/1.34:

abc = Appium::TouchAction.new
abc.swipe :start_x => startX, :start_y => startY, :end_x => endX, :end_y => endY, :duration => duration
abc.perform

Its weird, sometimes it ends up using one way or another, like it uses a different strategy depending on the coordinates given. I still didn’t explore it further in order to discover the behavior.

Those who are looking for the same kind of solution for android, Below video may help

1 Like

def swipeElement
$appiumDriver.swipe :start_x => 50, :start_y => 145, :end_x => 50, :end_y => 450, :duration => 500
end

I am using: Appium 1.3.4 and iOS 7.1 with iphone 5S simulator.
It taps on the x,y coordinate location but does not perform a swipe.

Am I missing anything?

This is a known issue that Apple broke with Xcode 5 over a year ago: https://github.com/appium/appium/issues/1696

It should work on a real device but I have not had luck with that yet.

Thanks @brentlavelle.

I am using
action.press(startX,startY).waitAction(500).moveTo(EndX,EndY).release().perform();
And it works for me to swipe in ipad2 simulator

2 Likes

@skaur1328

Thanks for your suggestion, i have tried a lot of solutions for real devices, none worked, except your solution.

Here is my code for anyone who needs an example.

if(driver.findElements(By.className("UIAPageIndicator")).get(0).getAttribute("value").equals("page 1 of 3")) {
			TouchAction tch = new TouchAction(driver);
			((TouchAction) tch ).press(startX,startY).waitAction(500).moveTo(endX,endY).release().perform();
		}

Be careful what wait time you use, since some scroll effects may need a higher value so they finish and not cause issues.
Also when swiping to a new page, use a large are to swipe, meaning start x and start y should be as far apart as possible.

ENV:
Appium 1.4.0
OSX : 10.10.5 (14F27)
iPhone 5 C 8.4.1

Thanks,
–Gery–

This works in Rubymine
Swipe up a little
Appium::TouchAction.new.swipe(start_x: 150, start_y: 400, end_x: 150, end_y: 100, duration: 500).perform

Simulator Version 9.2 (SimulatorApp-643) iOS 8.3
Appium Version 1.4.13 (Draco)
Xcode Version 7.2 (7C68)