# tap

Performs a tap gesture on:

* or the given element. It will **automatically scroll** if it can't be found.
* or the screen on a mobile device by providing `x` and `y` coordinates

Internally it uses:

* Element tap:

  <!-- -->

  * the `click` command for Web environments (Chrome/Safari browsers, or hybrid apps)
  * the Android [`mobile: clickGesture`](https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/android-mobile-gestures.md#mobile-clickgesture) or iOS [`mobile: tap`](https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-tap) for Natives apps, including the `scrollIntoView` command for automatic scrolling

* Screen tap:

  <!-- -->

  * the `action` command for Web environments (Chrome/Safari browsers, or hybrid apps)
  * the Android [`mobile: clickGesture`](https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/android-mobile-gestures.md#mobile-clickgesture) or iOS [`mobile: tap`](https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-tap) for Natives apps

This difference makes the `tap` command a more reliable alternative to the `click` command for mobile apps.

For Native Apps, this command differs from the `click` command as it will **automatically swipe** to the element using the `scrollIntoView command`, which is not supported for native apps with the `click` command. In hybrid apps or web environments, automatic scrolling is supported for both `click` and `tap` commands.

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.

For Screen taps

If you want to tap on a specific coordinate on the screen and you use a screenshot to determine the coordinates, remember that the the coordinates for iOS are based on the device's screen size, and not the screenshot size. The screenshot size is larger due to the device pixel ratio. The average device pixel ratio until the iPhone 8 and the current iPads is 2, for iPhones from the iPhone X the ratio is 3. This means that the screenshot size is 2 or 3 times larger than the device's screen size which means that ff you find the coordinates on the screenshot, divide them by the device pixel ratio to get the correct screen coordinates. For example:

```
const screenshotCoordinates = { x: 600, y: 900 };
const dpr = 3; // Example for iPhone 16
const screenCoordinates = {
    x: screenshotCoordinates.x / dpr,
    y: screenshotCoordinates.y / dpr
};
await browser.tap(screenCoordinates);
```

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

| Name                                        | Type         | Details                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options`<br />*optional*                   | `TapOptions` | Tap options (optional)                                                                                                                                                                                                                                                                                                                                                                                                         |
| **Element tap options**                     |              |                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `options.x`<br />*optional*                 | `number`     | Number (optional, mandatory if y is set)<br />**Only for SCREEN tap, not for ELEMENT tap**                                                                                                                                                                                                                                                                                                                                     |
| `options.y`<br />*optional*                 | `number`     | Number (optional, mandatory if x is set)<br />**Only for SCREEN tap, not for ELEMENT tap**                                                                                                                                                                                                                                                                                                                                     |
| **Screen tap options**                      |              |                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `options.direction`<br />*optional*         | `string`     | Can be one of `down`, `up`, `left` or `right`, default is `down`.<br />**Only for ELEMENT tap, not for SCREEN tap**<br />**MOBILE-NATIVE-APP-ONLY**                                                                                                                                                                                                                                                                            |
| `options.maxScrolls`<br />*optional*        | `number`     | The max amount of scrolls until it will stop searching for the element, default is `10`.<br />**Only for ELEMENT tap, not for SCREEN tap**<br />**MOBILE-NATIVE-APP-ONLY**                                                                                                                                                                                                                                                     |
| `options.scrollableElement`<br />*optional* | `Element`    | Element that is used to scroll 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 />**Only for ELEMENT tap, not for SCREEN tap**<br />**MOBILE-NATIVE-APP-ONLY** |

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

element.tap.example.js

```
it('should be able to tap an on element', async () => {
    const elem = $('~myElement')
    // It will automatically scroll to the element if it's not already in the viewport
    await elem.tap()
})
```

element.tap.scroll.options.example.js

```
it('should be able to swipe right 3 times in a custom scroll areas to an element and tap on the element', async () => {
    const elem = $('~myElement')
    // Swipe right 3 times in the custom scrollable element to find the element
    await elem.tap({
        direction: 'right',
        maxScrolls: 3,
        scrollableElement: $('#scrollable')
    })
})
```

screen.tap.example.js

```
it('should be able to tap on screen coordinates', async () => {
    await browser.tap({ x: 200, y: 400 })
})
```

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

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