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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Fill Out Forms With Puppeteer Locators

A practical guide to filling Puppeteer form controls with locators, choosing selectors, setting checkbox states, handling selects, and fixing common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await page.locator(selector).fill(value) to fill most form controls in Puppeteer. It supports inputs, textareas, selects, and contenteditable elements; pass true or false when setting checkboxes, radio buttons, or switches. Puppeteer’s page-interactions guide calls locators its recommended way to select and interact with elements. See the Puppeteer page-interactions guide and the Locator.fill() API reference (documentation version 25.12.0 when reviewed).

Fill a form with locator().fill()

Choose a selector that matches the page’s actual markup, then pass the value you want:

As an Amazon Associate I earn from qualifying purchases.

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

The selectors above are examples, not universal selectors. Replace them with selectors for the form you are automating. Puppeteer locators wait for an element to be present and in a suitable state for an action, and retry when readiness conditions are not met. An action can still time out if the element is absent or never becomes ready within the available time.

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

Choose a selector that identifies the right field

Prefer a meaningful label, accessible name, or stable attribute when the page provides one. Puppeteer supports CSS selectors as well as selector syntax for text, accessibility attributes, XPath, and open Shadow DOM. For example, the official getting-started guide demonstrates selecting a search field by accessible name:

await page.locator('::-p-aria(Search)').fill('automate beyond recorder');

That accessible name works only if the page exposes an element with that name. Inspect the target page’s markup and accessibility information rather than assuming a selector will work across sites. See Puppeteer’s getting-started guide and selector and interaction documentation.

Use the right value for each control

Text inputs, textareas, and contenteditable elements

Pass a string to fill() for text-like controls, including supported input, textarea, and contenteditable elements:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
await page.locator('input[name="email"]').fill('[email protected]');
await page.locator('textarea[name="message"]').fill('Hello');

Checkboxes, radio buttons, and switches

Pass a boolean to express the desired state. Use true to set the control and false to unset it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('input[name="terms"]').fill(true);
await page.locator('input[name="marketing"]:checked').fill(false);

Make sure the selector identifies the intended control. A radio group, for example, may need a selector for the specific option you want selected.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Select controls

locator().fill(value) supports select elements. You can also use page.select(selector, ...values) when you want to pass option values explicitly:

await page.select('select[name="country"]', 'US');

Puppeteer documents that page.select() triggers input and change events. For a multiple select, all supplied option values are considered; for a single select, only the first value is used. Neither approach is universally preferable: use the locator method for a consistent locator-first style, or page.select() when its explicit option-value interface suits the task. See the page.select() API reference.

Submit only after filling the intended fields

A locator action handles readiness checks for the action itself, but it cannot determine whether your chosen selector identifies the correct field or whether the submitted data is valid for the application. Keep the submit action separate so it is clear which fields were filled and when submission occurs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('input[name="email"]').fill('[email protected]');
await page.locator('input[name="terms"]').fill(true);
await page.locator('button[type="submit"]').click();

The button selector is illustrative. Choose a stable selector or accessible name that matches the form you are automating.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot locator form-filling failures

The action times out

  • Check that the selector matches an element on the current page and that navigation or rendering has completed.
  • Check whether the target becomes visible, enabled, and stable enough for the action. Locator actions perform readiness checks and retry, but they can time out if the required state is never reached.
  • Confirm that the form is not inside a frame or a closed Shadow DOM boundary that your selector cannot reach through the documented selector mechanisms.

The wrong field receives the value

  • Replace broad selectors with a label, accessible name, or stable field attribute that distinguishes the intended control.
  • Check whether the selector matches more than one element or points to a different control than expected.

A checkbox or radio option has the wrong state

  • Use a boolean with fill() to state the desired checked or unchecked value.
  • For radio groups, target the particular option rather than relying on a selector that could match another member of the group.

A select value is not applied

  • Verify that the value you pass is an option value on that select element.
  • For a multiple select, supply each desired value to page.select(); for a single select, only the first supplied value is used.

A legacy wait does not prevent an interaction failure

waitForSelector is a lower-level wait and does not automatically retry the later action. Locators combine finding an element with action readiness checks, so prefer a locator for this interaction pattern. See the page-interactions guide.

Or skip the browser setup

If you need a website screenshot rather than browser-driven form entry, ScreenshotNeo can return an image or PDF from one GET request. It does not fill out or submit forms. Example using cURL:

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. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. An MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

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

Frequently Asked Questions

Can I use a Puppeteer locator to fill a select element?

Yes. locator().fill(value) supports select elements; page.select(selector, ...values) is another documented option.

Does fill() work for checkboxes?

Yes. Pass true or false to set the desired state.

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.