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
andy
coordinates
Internally it uses:
- Element tap:
- the
click
command for Web environments (Chrome/Safari browsers, or hybrid apps) - the Android
mobile: clickGesture
or iOSmobile: tap
for Natives apps, including thescrollIntoView
command for automatic scrolling
- the
- Screen tap:
- the
action
command for Web environments (Chrome/Safari browsers, or hybrid apps) - the Android
mobile: clickGesture
or iOSmobile: tap
for Natives apps
- the
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.
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);