DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Tap an Element in Puppeteer

Tap a selector with page.tap(), or use a locator to wait for the element to be ready. Here’s how touch differs from mouse input, how to emulate a device, and what to check when a tap fails.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await page.tap('button.submit') to send a touch tap to the first matching element. Puppeteer scrolls it into view if needed and taps its center. For ordinary element interactions, Puppeteer recommends locators, which wait for the element and for it to be ready to act on.

Tap an element with a selector

The direct Page API takes a selector string:

await page.tap('button.submit');

page.tap(selector) scrolls the matched element into view when necessary, then taps its center through Puppeteer’s touchscreen input. It throws if the selector matches no element. If more than one element matches, it taps the first one, so use a selector specific to the intended target. Puppeteer Page.tap() reference.

As an Amazon Associate I earn from qualifying purchases.

Prefer a locator for a normal element workflow

Puppeteer’s interaction guide recommends locators for selecting and interacting with elements. A locator automatically waits for the element to be present and in an actionable state:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('button.submit').tap();

Choose this form when the page may still be rendering or the target may not yet be ready. Use page.tap(selector) when its concise selector-based behavior fits the step. If your project supports multiple Puppeteer releases, check the installed version’s API before relying on a method.

Puppeteer page interactions guide.

Choose touch, mouse, or coordinates

  • Touch a selected element: Use page.locator(selector).tap() for locator-driven interaction, or page.tap(selector) for the direct Page method. Both target the element rather than requiring you to calculate its position.
  • Touch an element handle: If you already hold an ElementHandle, call await elementHandle.tap(). Puppeteer scrolls it into view if needed and taps its center. It throws if the element has detached from the DOM; reacquire the handle after page changes. ElementHandle.tap() reference.
  • Touch a viewport coordinate: Call await page.touchscreen.tap(x, y), where x is the horizontal and y the vertical position. This dispatches touchstart followed by touchend. Use it when the position itself is what matters. Touchscreen.tap() reference.
  • Send a mouse click: Use page.click(selector) when the page should receive mouse input. Puppeteer treats mouse and touch as distinct input mechanisms; a click is not a substitute when you need to test touch behavior. Page interactions guide.

Emulate a mobile device before navigating

For a mobile-device context, emulate the device before opening the page. Puppeteer’s page.emulate() sets the user agent and viewport; doing it before navigation avoids changing those settings after the site has loaded, which can affect its behavior.

import puppeteer, {KnownDevices} from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.emulate(KnownDevices['iPhone 17 Pro']);
  await page.goto('https://example.com');
  await page.locator('button.submit').tap();
} finally {
  await browser.close();
}

Use a device name available in the KnownDevices export for the Puppeteer version installed in your project. The current Page.emulate() reference shows the iPhone 17 Pro example.

Troubleshoot taps that do not work

  • No matching element: The direct Page method throws if no element matches. Check the selector and whether the target exists when the action runs; a locator can wait for an element to appear.
  • The wrong matching element is tapped: page.tap(selector) chooses the first match. Narrow the selector to identify the intended element.
  • An element handle is detached: The page may have replaced or removed the node. Query for a fresh handle after the page changes, or use a locator-based interaction.
  • The page reacts differently than expected: Verify the input type. page.click() sends mouse input; the tap APIs send touch input.
  • The mobile layout is unexpected: Configure emulation before navigation. Changing the user agent or viewport after loading can affect site behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a screenshot rather than testing a touch interaction, ScreenshotNeo returns a screenshot or PDF from one GET request. It does not tap page elements, but can remove cookie banners, newsletter popups and chat widgets before capture. Bot checks, blank pages and failed loads are not billed; an MCP server lets AI agents take screenshots; 1,000 screenshots a month are free with no card, and paid plans start at $5 for 3,000.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

cURL example and ScreenshotNeo API documentation:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Sign up for 1,000 free screenshots a month, with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.