October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Interact with Web Pages Using Puppeteer

A practical Puppeteer guide to navigating pages, choosing selectors, interacting with controls, waiting for the right state, and troubleshooting common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To interact with a web page using Puppeteer, launch or connect to a browser, create a Page, navigate to the target URL, locate the control, perform an action, and wait for the result you expect. For current Puppeteer guidance, use locators for clicks and form input: they wait for an element to be present and in a suitable state when the action runs. The examples below follow the Puppeteer Getting Started guide, labeled version 25.12.0; selectors must be adapted to the site you automate.

Install Puppeteer and open a page

Puppeteer is a JavaScript library for browser automation. Its official overview describes automation of Chrome and Firefox through the Chrome DevTools Protocol and WebDriver BiDi. Most interactions happen through a Page, the tab-level surface used to navigate, find controls, and inspect content. See the Puppeteer overview and the Getting Started guide.

As an Amazon Associate I earn from qualifying purchases.

In a Node.js project, install the package with npm install puppeteer, then save this as an ES module file such as interact.mjs and run it with node interact.mjs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://developer.chrome.com');
  await page.setViewport({ width: 1280, height: 800 });

  await page.locator('::-p-aria(Search)').fill('Puppeteer');
  await page.locator('button[type="submit"]').click();

  const title = await page.title();
  console.log({ title, url: page.url() });
} finally {
  await browser.close();
}

This illustrates the flow, not a guarantee that a particular selector matches a site. Replace the URL, accessible name, and button selector with controls that actually exist on your target page. The guide’s current documented example uses an accessibility selector for search and a submit button; check the live documentation if you are working with another Puppeteer version.

#1 Best Overall
Sale
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

Browser and page lifecycle

  • puppeteer.launch() starts a browser that this script owns.
  • browser.newPage() creates a tab for navigation and interaction. A browser can have multiple pages.
  • page.goto(url) navigates to the requested URL.
  • The finally block closes the browser even if an interaction throws an error. If your script connects to a browser owned by another process instead, follow the connection lifecycle rather than closing a browser it does not own.

Find and interact with page elements

Use locators for actions

Puppeteer’s page-interactions guide recommends locators for selecting elements and performing actions. A locator resolves the target when an action is performed and automatically waits for the element to be present and in the appropriate state. This is a practical default for clicking and filling fields, rather than selecting too early and acting on a stale or missing element. See Puppeteer’s page interactions guide.

await page.locator('input[name="email"]').fill('[email protected]');
await page.locator('button[type="submit"]').click();

Use the actual field and button selectors from the page. For a select control, Puppeteer also documents page.select(); for a pointer-style interaction, use hover(); keyboard and mouse input are available when the interaction requires them. The Page API documents these methods at the Page class reference.

Rank #2
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere

Choose a selector that expresses the target

  • Accessibility name or role: useful when the page exposes a stable, meaningful accessible name. Puppeteer supports selectors such as ::-p-aria(Search).
  • Text: useful when the target is identified by visible wording, provided the wording is distinctive and stable.
  • CSS: concise for stable attributes or structure, such as button[type="submit"] or input[name="email"].
  • XPath and shadow DOM: Puppeteer supports syntax for these cases too. Use them when the target structure calls for them; neither is universally preferable.

Selector syntax is only a way to describe a target. It cannot make an absent control appear, and selectors based on fragile classes or changing text may need maintenance when a site changes.

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

Use element handles only when you need lower-level control

page.waitForSelector() remains useful when you need an explicit wait or an element handle. It is lower-level than locators: it does not automatically retry an action if that action fails, and handles returned by it should be disposed when no longer needed to avoid memory leaks. Older calls such as page.click(selector) and page.type(selector, text) remain documented for backwards compatibility, but locators are the recommended starting point for current interactions.

Rank #3
Sale
Logitech M185 Compact Ambidextrous Wireless Mouse with Rubber Grips - Blue
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

Wait for the result of an interaction

When a click causes navigation

If clicking a link or submitting a form navigates to another document, start waiting for navigation before the click can trigger it. Running both promises together avoids a race in which navigation begins before the waiter is registered:

const [response] = await Promise.all([
  page.waitForNavigation(),
  page.locator('a.next-page').click(),
]);

console.log('Navigated to:', page.url());

Replace a.next-page with the site’s real selector. The response can be null in cases where the navigation does not produce a response, so verify the resulting URL or page state instead of treating a non-null response as the only success condition.

Rank #4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
  • Computer mouse for easily navigating a computer interface; click, scroll, and more
  • USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
  • High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
  • 3 buttons offer effortless fingertip control
  • Plug-and-go ready for instant use

When the page updates without navigating

Single-page applications often update a result region without replacing the document. In that case, waiting for navigation is the wrong signal. Wait for the expected visible state instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('button[type="submit"]').click();
await page.locator('[data-testid="search-results"]').wait();

The selector here is an example; use a result element present on the target site. Puppeteer also documents waits for selectors, functions, requests, and responses. Choose the wait that corresponds to the behavior you need to observe, rather than inserting a fixed delay and hoping the page finishes in time.

Best Value
Sale
Acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable 1600 DPI
  • 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
  • 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
  • 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
  • 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
  • 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Read page information and verify success

After an action, check the state the task depends on. For example, inspect the current URL, read the title, or retrieve text from the result element:

const currentUrl = page.url();
const pageTitle = await page.title();
const resultText = await page.locator('[data-testid="search-results"]').evaluate(
  element => element.textContent
);

console.log({ currentUrl, pageTitle, resultText });

page.evaluate() runs a function in the page’s JavaScript context and is useful for reading or manipulating page-context state. For interactions intended to behave like user input, prefer locators and browser input methods. A screenshot can help diagnose what rendered, but an image alone does not prove that the intended action succeeded; also verify the URL, visible result, or other relevant state. Puppeteer’s Page API includes title(), url(), evaluate(), screenshot(), and pdf().

Common interaction problems and fixes

Symptom Likely cause What to do
Locator does not find the control The selector does not match the target page, the accessible name differs, or the control has not appeared yet. Inspect the page’s actual markup and accessible name; use a selector that matches it, and wait for the target state when content loads asynchronously.
Click succeeds but expected content is missing The action may have triggered an in-page update rather than navigation, or the script checked too soon. Wait for the result element or another specific state instead of assuming navigation or relying on a fixed delay.
Navigation wait times out or misses the navigation The click and wait may have been started in the wrong order, or the action does not cause document navigation. For real navigation, register waitForNavigation() and the click together with Promise.all(). For in-page changes, wait for the resulting state instead.
An element handle becomes stale or memory use grows The DOM may have changed after the handle was obtained, or handles are being retained. Prefer locators for actions. If using waitForSelector() and handles, reacquire after DOM changes and dispose handles when finished.
A screenshot looks right but the task still fails A screenshot shows pixels, not whether the intended control action or application state was completed. Assert the relevant URL, result text, response, or other application state in addition to capturing an image.

Or skip the browser setup

If the task is simply to capture a page rather than automate its controls, ScreenshotNeo provides a one-request screenshot API. For example, this cURL call saves a WebP capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. It also has an MCP server for AI agents, and the Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Visit ScreenshotNeo for product details, or sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Puppeteer interact with both Chrome and Firefox?

The official overview describes Puppeteer automation for Chrome and Firefox using the Chrome DevTools Protocol and WebDriver BiDi. The exact browser and protocol setup depends on the Puppeteer version and configuration.

Does every Puppeteer click cause a page navigation?

No. A click may update content in place. Wait for navigation only when a document navigation is expected; otherwise wait for the specific resulting state.

Quick Recap

SaleBestseller No. 1
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Product carbon footprint: 3.97 kg CO2e; Contoured shape: Gives you more comfort and control
$14.85
SaleBestseller No. 3
Bestseller No. 4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Computer mouse for easily navigating a computer interface; click, scroll, and more; 3 buttons offer effortless fingertip control
$9.70

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.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.