# longPress

Performs a long press gesture on the given element on the screen.

This issues a WebDriver `action` command for the selected element. It is based on the `click` command, except for iOS web context, there we use a script to simulate the long press due to the lack of support for long press gestures in webview.

info

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.

## Usage[​](#usage "Direct link to Usage")

```
await $(selector).longPress({ x, y, duration })
```

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

| Name                               | Type               | Details                                                              |
| ---------------------------------- | ------------------ | -------------------------------------------------------------------- |
| `options`<br />*optional*          | `LongPressOptions` | Long press options (optional)                                        |
| `options.x`<br />*optional*        | `number`           | Number (optional)                                                    |
| `options.y`<br />*optional*        | `number`           | Number (optional)                                                    |
| `options.duration`<br />*optional* | `number`           | Duration of the press in ms, default is 1500 ms<br />**MOBILE-ONLY** |

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

longpress.offset.js

```
it('should demonstrate a longPress using an offset on the iOS Contacts icon', async () => {
    const contacts = $('~Contacts')
    // opens the Contacts menu on iOS where you can quickly create
    // a new contact, edit your home screen, or remove the app
    // clicks 30 horizontal and 10 vertical pixels away from location of the icon (from center point of element)
    await contacts.longPress({ x: 30, y: 10 })
})
```

longpress.example.js

```
it('should be able to open the contacts menu on iOS by executing a longPress of 5 seconds', async () => {
    const contacts = $('~Contacts')
    // opens the Contacts menu on iOS where you can quickly create
    // a new contact, edit your home screen, or remove the app
    await contacts.longPress({ duration: 5 * 1000 })
})
```

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

![Support for ios](data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFl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Njg4LTIzLjk2N2MtMzguMTg4LDAtNzYuMDg0LDI0Ljg2MS0xMDAuNzY2LDI0Ljg2MUM4OS4zMyw2MDguNzMsMCw0NTUuNjY2LDAsMzMyLjYyOAoJYzAtMTIxLjA1Miw3NS42MTItMTg0LjU1NCwxNDYuNTMzLTE4NC41NTRDMTkyLjYzOCwxNDguMDc0LDIyOC40MTYsMTc0LjY2MiwyNTIuMzg1LDE3NC42NjJ6Ii8+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.
