# How to automate swipe gestures in iOS 8

**URL:** <https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684>\
**Category:** Support\
**Created:** [August 20, 2015, 11:46am UTC](https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684 "2015-08-20T11:46:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karunakaran\_M](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/ea5d25/32.png) [@Karunakaran\_M](https://discuss.appium.io/u/Karunakaran_M)\
**Post date:** [August 20, 2015, 11:46am UTC](https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684/1 "2015-08-20T11:46:29Z")

</div>

I need to automate swipe gesture for both side(Right To Left and Left to Right) in iOS mobile app.

```
 I am using appium version 1.4.8 , iOS simulator 6 and platform version as 8.3.

 I am writing test cases using java language.

 I have tried with below coding for swipe gestures. But, the swipe action doesn't happens for me.

  public void swipeLeftToRight(AppiumDriver driver) {
      Dimension size = driver.manage().window().getSize();
      int endx = (int) (size.width * 0.8);
      int startx = (int) (size.width * 0.20);
      int starty = size.height / 2;

      driver.swipe(startx, starty, endx, starty, 1000);
  }

  public void swipeRightToLeft(AppiumDriver driver) {
      Dimension size = driver.manage().window().getSize();
      int startx = (int) (size.width * 0.8);
      int endx = (int) (size.width * 0.10);
      int starty = size.height / 2;

      driver.swipe(startx, starty, endx, starty, 1000);
  }
```

---

<div class="post-metadata">

**Author:** ![amitjaincoer191](https://discuss.appium.io/user_avatar/discuss.appium.io/amitjaincoer191/32/5339_2.png) [@amitjaincoer191](https://discuss.appium.io/u/amitjaincoer191)\
**Post date:** [August 20, 2015, 1:56pm UTC](https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684/3 "2015-08-20T13:56:28Z")

</div>

For Android This works fine

public class TouchActions{

```
public static AndroidDriver<WebElement> _driver;

@BeforeClass
public void setUpAppium() throws InterruptedException, IOException {
	
	DesiredCapabilities capabilities = new DesiredCapabilities();   
	AppCapabilitiesSetUp(capabilities);
	_driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);	
}

@Test
public void TouchActionsTest() throws InterruptedException{
	// Wait for first app to launch
	Thread.sleep(10000);
    
	// Press Home Key
	_driver.sendKeyEvent(AndroidKeyCode.HOME);
	Thread.sleep(3000);
           // Press Menu Button
	_driver.findElementByAccessibilityId("Apps").click();
	
	TouchAction tAction=new TouchAction(_driver);
	int startx = _driver.findElement(By.name("Email")).getLocation().getX();
	int starty = _driver.findElement(By.name("Email")).getLocation().getY();
	int endx = _driver.findElement(By.name("Dev Settings")).getLocation().getX();
	int endy = _driver.findElement(By.name("Dev Settings")).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(); 
	
	Thread.sleep(1000);
	
	//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();
	
	Thread.sleep(1000);
}

@AfterClass(alwaysRun=true)
public void teardown(){
	_driver.closeApp();
	_driver.quit();
}

public DesiredCapabilities AppCapabilitiesSetUp(DesiredCapabilities cap){
	cap.setCapability(CapabilityType.BROWSER_NAME,"");
	cap.setCapability("platformVersion","4.4.4");
	cap.setCapability("platformName","Android");
	cap.setCapability("deviceName","emulator-5554");
	cap.setCapability("appPackage","appPackage");
	cap.setCapability("appActivity","appActivity");						
	return cap;
	
}

```

}

---

<div class="post-metadata">

**Author:** ![Karunakaran\_M](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/ea5d25/32.png) [@Karunakaran\_M](https://discuss.appium.io/u/Karunakaran_M)\
**Post date:** [August 21, 2015, 5:02am UTC](https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684/4 "2015-08-21T05:02:50Z")

</div>

@amitjaincoer191 Can you tell me solution for iOS

---

<div class="post-metadata">

**Author:** ![Karunakaran\_M](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/ea5d25/32.png) [@Karunakaran\_M](https://discuss.appium.io/u/Karunakaran_M)\
**Post date:** [August 31, 2015, 12:01pm UTC](https://discuss.appium.io/t/how-to-automate-swipe-gestures-in-ios-8/5684/5 "2015-08-31T12:01:21Z")

</div>

@amitjaincoer191 @amitjaincoer191 Here is my scenario

Scenario 1:-

1. There are 20 article in the page
2. Only 5 articles are displayed. Other articles are displayed when you scroll
3. How can i scroll with x and y co-ordinates and find an expected article. I want to reach 20th article and click it.
4. This is list of articles page, Here you see 5 articles are displayed.

 ![](https://discuss.appium.io/uploads/default/original/2X/0/0ed8104a16d93c893abf314a6f4b16d2b3db808a.png) 

Scenario 2:-

1. Article content is displayed
2. There are more paragraphs are displayed in an article. In centre of the page , mobile ad(Image) will be displayed.
3. Mobile Ad(Image) will be displayed only when we scroll to position of centre of an article. I want to verify that image is present or not.
4. This is a article page, When you scroll, Mobile Ad(image) will be displayed  
 ![](https://discuss.appium.io/uploads/default/original/2X/4/4a7b42be86c0ac130ed90071551fb8912a8b0403.png)

How can i do it above scenarios?
