How to perform scroll gesture for iOS mobile app in iOS simulator?

@amitjaincoer191, Not like that I have a single image, I need to swipe that image and go to the next image. Its like image gallery swiping.

Try like this
// Make sure right view should be present when this code is executed
// perform horizontal swipe from right to left so that next image will appear
int x = driver.manage().window().getSize().getHeight();
int y = driver.manage().window().getSize().getWidth();
driver.swipe(x/3+300, y/2-150, x/3, y/2-150, 2000);

  1. I have tried with above code. It throws below error message.
    Error Message:-
    org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript. (WARNING: The server did not provide any stacktrace information)

  2. It throws error in below line
    //driver.swipe(x/3+300, y/2-150, x/3, y/2-150, 2000);

You are right scroll gesture is not working when we are passing coordinates we can raise a bug with appium for that

Here is the code on UICatalog app and it works for scrolling. Make sure u r using java client 3.1 version

@Test
public void setUp() throws Exception {
protected static IOSDriver driver;
File app = new File("/Users/Library/Developer/Xcode/DerivedData/UICatalog-axxvcppluaedjmfkuzvxoncaguwk/Build/Products/Debug-iphonesimulator/UICatalog.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“platformVersion”, “8.1”);
capabilities.setCapability(“platformName”, “ios”);
capabilities.setCapability(“deviceName”, “iPhone Simulator”);
capabilities.setCapability(“app”,"/Users/amit.ja/Library/Developer/Xcode/DerivedData/UICatalog-axxvcppluaedjmfkuzvxoncaguwk/Build/Products/Debug-iphonesimulator/UICatalog.app");
capabilities.setCapability(“app”, app.getAbsolutePath());

      driver = new IOSDriver<WebElement>(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
      WebDriverWait wait = new WebDriverWait(driver,150);
      
      driver.findElementByAccessibilityId("UICatalog").click();
      //int x1 = driver.findElementByAccessibilityId("Alert Controller").getLocation().getX();
      //int y1 = driver.findElementByAccessibilityId("Alert Controller").getLocation().getY();
      //int x2 = driver.findElementByAccessibilityId("Sliders").getLocation().getX();
      //int y2 = driver.findElementByAccessibilityId("Sliders").getLocation().getY();
      //System.out.println("x1,y1 " + x1 + "," + y1 + " x2,y2 " + x2 + "," + y2);
      TouchAction act = new TouchAction(driver);
      //act.press(100,550).moveTo(100,100).release().perform();
      act.press(driver.findElementByAccessibilityId("Sliders")).moveTo(driver.findElementByAccessibilityId("Alert Controller")).release().perform();
      Thread.sleep(4000);
    }

@amitjaincoer191, Thanks for your information, I have really got struck with scroll and swipe gestures more than a week. I have tried so many solution for gestures, still its not working. I will upgrade java client version and give a try with above code.

@Selvi_Ranganathan

scrollTo() and scrollToExact() methods work on UIATableView elements which contains UIATableCell elements.
What you need to do is, first find a UIATableView element using
WebElement tableView = driver.findElement(MobileBy.xpath("//UIATableView[3]"))
then do
tableView.scrollTo(“DesiredText”) - and this will take you that element and return you WebElement having text on which you intend to scroll.

@vipuljain33 WebElement doesn’t seem to have scrollTo method in it.

These are methods inside AppiumDriver / AndroidDriver Class
scrollTo() and scrollToExact() methods

What you have to do here is find tableView element and then cast the WebElement to Android or IOSElement and then perform scroll operation on it.
WebElement parentElem = driver.findElement(MobileBy.xpath("//UIATableView[3]"));
((IOSElement)parentElem).scrollTo(“text”);

Hope this answers your question

Guys, Any success on swiping from left to right and vice versa?

I am using
iOS_Driver.swipe(…)

but no success.?

Try driver.swipe(100,250,50,250,500); to swipe from Left to right.

i tried this and it swipes down, how does it make sense?

Any suggestions on scrollTo options on XCUITest elements?

public static void scrollios(String move){
//down,up,left,right
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, move);
js.executeScript(“mobile: scroll”, scrollObject);

}

Inside the move parameter mention the direction:up, down,right and left

public static void scrollios(String move){
//down,up,left,right
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put(“direction”, move);
js.executeScript(“mobile: scroll”, scrollObject);

}
Inside the move parameter mention the direction:up, down,right and left

1 Like

If ur using swipe functionalty use negative in end y value…
driver.swipe(150,350,150,-100,300);

hey frnd, i am able to swipe left or right, but it always swipe 2nd row of the cell, any idea to make it dynamic?

using JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put(“direction”, move);
js.executeScript(“mobile: scroll”, scrollObject);

Using Java Script Executor it is actually scrolling down the Notification panel of Wifi not the Native Application.
Any Idea how to perform scrolling in application ??

Details can be found on below link:

http://appium.io/docs/en/writing-running-appium/touch-actions/