# swipe

Swipe in a specific direction within viewport or element for Desktop/Mobile Web **AND** Mobile Native Apps.

info

Swiping for Mobile Native Apps is based on the W3C-actions protocol, simulating a finger press and movement. This is different from the [`mobile: scrollGesture`](https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/android-mobile-gestures.md#mobile-scrollgesture) for Android or [`mobile: scroll`](https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-scroll) for iOS command which is based on the Appium Driver protocol and is only available for mobile platforms in the NATIVE context.

This command only works with the following up-to-date components:

* Appium server (version 2.0.0 or higher)
* `appium-uiautomator2-driver` (for Android)
* `appium-xcuitest-driver` (for iOS)

Make sure your local or cloud-based Appium environment is regularly updated to avoid compatibility issues.

Swiping based on coordinates

Avoid using `from` and `to` options unless absolutely necessary. These are device-specific and may not work consistently across devices. Use the `scrollableElement` option for reliable swipes within an element.

## Parameters[​](#parameters "Direct link to Parameters")

| Name                                                                                                                     | Type              | Details                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------------------------------------------------------------------------------------------------------------ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `options`<br />*optional*                                                                                                | `object, boolean` | options for `browser.swipe()`. Default for desktop/mobile web:<br />`{ direction: 'up', duration: 1500, percent: 0.95, scrollableElement: WebdriverIO.Element }`                                                                                                                                                                                                                                                                                                                                                 |
| `options.direction`<br />*optional*                                                                                      | `string`          | Can be one of `down`, `up`, `left` or `right`, default is `up`.<br />**MOBILE-NATIVE-APP-ONLY**                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **Down**                                                                                                                 |                   | **Starting Point:**<br />You place your finger towards the top of the screen.<br />**Movement:**<br />You slide your finger downwards towards the bottom of the screen.<br />**Action:**<br />This also varies by context:<br />- On the home screen or in applications, it typically scrolls the content upwards.<br />- From the top edge, it often opens the notifications panel or quick settings.<br />- In browsers or reading apps, it can be used to scroll through content.                             |
| **Left**                                                                                                                 |                   | **Starting Point:**<br />You place your finger on the right side of the screen.<br />**Movement:**<br />You slide your finger horizontally to the left.><br />**Action:**<br />The response to this gesture depends on the application:<br />- It can move to the next item in a carousel or a set of images.<br />- In a navigation context, it might go back to the previous page or close the current view.<br />- On the home screen, it usually switches to the next virtual desktop or screen.             |
| **Right**                                                                                                                |                   | **Starting Point:**<br />You place your finger on the left side of the screen.<br />**Movement:**<br />You slide your finger horizontally to the right.<br />**Action:**<br />Similar to swiping left, but in the opposite direction:<br />-- It often moves to the previous item in a carousel or gallery.<br />- Can be used to open side menus or navigation drawers in apps.<br />- On the home screen, it typically switches to the previous virtual desktop.                                               |
| **Up**                                                                                                                   |                   | **Starting Point:**<br />You place your finger towards the bottom of the screen.<br />**Movement:**<br />You slide your finger upwards towards the top of the screen.><br />**Action:**<br />Depending on the context, different actions can occur:<br />- On the home screen or in a list, this usually scrolls the content downwards.<br />- In a full-screen app, it might open additional options or the app drawer.<br />- On certain interfaces, it could trigger a 'refresh' action or open a search bar. |
| `options.duration`<br />*optional*                                                                                       | `number`          | The duration in milliseconds for the swipe. Default is `1500` ms. The lower the value, the faster the swipe.                                                                                                                                                                                                                                                                                                                                                                                                     |
| `options.scrollableElement`<br />*optional*                                                                              | `Element`         | Element that is used to swipe within. If no element is provided it will use the following selector for iOS `-ios predicate string:type == "XCUIElementTypeApplication"` and the following for Android `//android.widget.ScrollView'`. If more elements match the default selector, then by default it will pick the first matching element.<br />**MOBILE-NATIVE-APP-ONLY**                                                                                                                                      |
| `options.percent`<br />*optional*                                                                                        | `number`          | The percentage of the (default) scrollable element to swipe. This is a value between 0 and 1. Default is `0.95`.<br />**NEVER** swipe from the exact top\|bottom\|left\|right of the screen, you might trigger for example the notification bar or other OS/App features which can lead to unexpected results.<br />This has no effect if `from` and `to` are provided.                                                                                                                                          |
| **The below values **ONLY** have an effect if the `scrollableElement` is **NOT** provided, otherwise they are ignored.** |                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `options.from`<br />*optional*                                                                                           | `object`          | The x and y coordinates of the start of the swipe. If a `scrollableElement` is provided, then these coordinates have no effect.                                                                                                                                                                                                                                                                                                                                                                                  |
| `options.from.x`<br />*optional*                                                                                         | `number`          | The x-coordinate of the start of the swipe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `options.from.y`<br />*optional*                                                                                         | `number`          | The y-coordinate of the start of the swipe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `options.to`<br />*optional*                                                                                             | `object`          | The x and y coordinates of the end of the swipe. If a `scrollableElement` is provided, then these coordinates have no effect.                                                                                                                                                                                                                                                                                                                                                                                    |
| `options.to.x`<br />*optional*                                                                                           | `number`          | The x-coordinate of the end of the swipe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `options.to.y`<br />*optional*                                                                                           | `number`          | The y-coordinate of the end of the swipe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |

## Examples[​](#examples "Direct link to Examples")

swipe.js

```
it('should execute a default swipe', async () => {
    // Default will be a swipe from the bottom to the top, meaning it will swipe UP
    await browser.swipe();
});
```

swipe.with.options.js

```
it('should execute a swipe with options', async () => {
    await browser.swipe({
        direction: 'left',                  // Swipe from right to left
        duration: 5000,                     // Last for 5 seconds
        percent: 0.5,                       // Swipe 50% of the scrollableElement
        scrollableElement: $('~carousel'),  // The element to swipe within
    })
});
```

## Support[​](#support "Direct link to Support")

![Support for ios](data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub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M4OS4zMyw2MDguNzMsMCw0NTUuNjY2LDAsMzMyLjYyOAoJYzAtMTIxLjA1Miw3NS42MTItMTg0LjU1NCwxNDYuNTMzLTE4NC41NTRDMTkyLjYzOCwxNDguMDc0LDIyOC40MTYsMTc0LjY2MiwyNTIuMzg1LDE3NC42NjJ6Ii8+Cjwvc3ZnPgo=) ![Support for android](/assets/images/android-d941e94d5839760141de31c8446b67ce.svg)

**Supported platforms:** iOS, Android

note

Refer to the official [Appium driver documentation](https://appium.io/docs/en/latest/ecosystem/) to see which driver versions support this command.
