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

Handle Puppeteer uploads in one of two ways: locate an <input type="file"> and call uploadFile(), or wait for a page-triggered chooser before clicking the upload button, then call accept(). The file must exist in the environment running (or connected to) Chrome; use absolute paths when connecting to remote Chrome.

Choose the upload method that matches the page

The page’s HTML and behavior determine the correct API:

  • Visible or hidden file input: find the input[type=file] element and call ElementHandle.uploadFile().
  • Button that opens a native chooser: register page.waitForFileChooser() before clicking, then accept one or more paths.

Puppeteer’s Files guide puts the direct-input workflow plainly: “For uploading files, you need to locate a file input element and call ElementHandle.uploadFile.” Puppeteer recommends locators for general element interaction, but the documented locator filling methods are not a file-selection API. Use the lower-level element-handle method for file inputs.

Upload through an input element

Minimal runnable example

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();

await page.goto('https://example.com/upload', {waitUntil: 'networkidle2'});

const fileElement = await page.waitForSelector('input[type=file]');
await fileElement.uploadFile('./fixtures/report.pdf');

// If the page displays a submit control:
await page.click('button[type=submit]');
await page.waitForNetworkIdle();

await browser.close();

uploadFile() accepts one or more paths as strings. For a multi-file input, pass multiple paths:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
await fileElement.uploadFile(
  './fixtures/photo-1.jpg',
  './fixtures/photo-2.jpg'
);

The method sets the input’s selected files; it does not itself click Submit or guarantee that the application has finished processing them. After assignment, follow the site’s normal flow: click its upload button, wait for a response or a success element, and assert the result.

Use a specific selector

If the page has several file inputs, select the one identified by its name, id, or data attribute:

const fileElement = await page.waitForSelector(
  'input[type=file][name="resume"]'
);
await fileElement.uploadFile('/absolute/path/to/resume.pdf');

Do not assume a file input is visibly rendered. Many applications hide it behind a styled button; direct assignment still works when the element is present in the DOM.

Wait for the application’s upload result

Waiting for navigation is not always correct: modern applications often upload with fetch or XHR and remain on the same URL. Prefer a response predicate, a success selector, or an application-specific status:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await Promise.all([
  page.waitForResponse(response =>
    response.url().includes('/api/uploads') &&
    response.request().method() === 'POST' &&
    response.ok()
  ),
  page.click('button[type=submit]'),
]);

await page.waitForSelector('[data-upload-status="complete"]');

Adjust the URL and selector to the application under test. A generic networkidle2 wait can be misleading when analytics, polling, or long-lived connections keep the page busy.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Handle a page-triggered file chooser

Register the waiter before the click

When a button opens a chooser, the listener must be ready before the event occurs. Puppeteer’s recommended pattern uses Promise.all:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('https://example.com/upload', {waitUntil: 'domcontentloaded'});

const [fileChooser] = await Promise.all([
  page.waitForFileChooser(),
  page.click('#upload-file-button'),
]);

await fileChooser.accept(['/tmp/myfile.pdf']);
await page.waitForSelector('[data-upload-status="complete"]');
await browser.close();

Calling waitForFileChooser() after the click creates a race: the chooser may already have opened, so the promise can time out.

Accept multiple files or cancel

accept() receives an array of paths:

await fileChooser.accept([
  '/tmp/invoice.pdf',
  '/tmp/receipt.pdf',
]);

To dismiss the chooser instead, call:

await fileChooser.cancel();

A chooser that is neither accepted nor canceled can block subsequent chooser dialogs because the browser permits only one open chooser at a time. Always resolve it, including in error-handling paths.

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

Chooser limitations

  • waitForFileChooser() must run before the chooser opens and does not return one that is already active.
  • Puppeteer does not support intercepting dialogs opened through DOM APIs such as window.showOpenFilePicker. That API is a different browser capability from the traditional input/chooser flow.
  • In headful mode, Puppeteer handles the native picker without displaying the operating-system dialog to the user. A test waiting for a visible dialog may therefore appear stuck even though automation is working.

Paths, working directories, and remote Chrome

Both upload APIs resolve relative paths against the Node.js process’s current working directory, not necessarily the directory containing your test file. Make the location explicit when tests run from a runner, monorepo, or CI job:

import path from 'node:path';

const filePath = path.resolve(process.cwd(), 'fixtures/report.pdf');
await fileElement.uploadFile(filePath);

When your script connects to remote Chrome, the path must be absolute and refer to a file available to the environment expected by Puppeteer’s upload implementation. A file on your laptop is not automatically present in a container, VM, or remote browser host. Package the fixture into the test image, mount it, or copy it before starting the test.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

The upload and chooser APIs do not verify that a path exists before accepting it. Treat file availability as a precondition and check it yourself:

import {access} from 'node:fs/promises';

await access(filePath); // throws early if the fixture is missing
await fileElement.uploadFile(filePath);

Use platform-aware path construction rather than hard-coding separators. For reproducible CI runs, log the resolved path (without exposing confidential filenames or data) and the process working directory.

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

Reliable upload test design

Make the page ready before selecting a file

  • Navigate with an appropriate readiness condition such as domcontentloaded or a known application selector.
  • Wait for the actual file input or upload button, not an arbitrary timeout.
  • If the control is inside an iframe, obtain the correct frame first and query its input there.

Assert the outcome, not just the API call

A successful uploadFile() call only means Puppeteer assigned paths to the input. Verify the application’s response: a success message, a rendered filename, an enabled Continue button, a successful upload response, or a server-side record queried through your test interface.

Control file contents and size

Keep deterministic fixtures under version control or create them during test setup. Include representative formats, an empty file where validation matters, and boundary-size files when the application enforces limits. Do not place production secrets in fixtures or print their contents in test logs.

Clean up browser resources

Use a try/finally block in suites so a failed assertion does not leave Chrome processes running:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const browser = await puppeteer.launch();
try {
  // navigation, selection, upload, and assertions
} finally {
  await browser.close();
}
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

“No element found” or a selector timeout

Cause: the input is rendered later, has a different selector, or lives in an iframe. Fix: inspect the DOM, wait for the application’s ready state, target a stable attribute, and query the correct frame. Do not replace the wait with a large fixed sleep unless the site genuinely has a known delay.

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.

The click times out and no chooser arrives

Cause: the button is covered, disabled, detached, or does not open a traditional chooser. Fix: wait for visibility/enabled state, click the actual control, and confirm the page uses an input type=file or compatible chooser event. For showOpenFilePicker, Puppeteer’s file-chooser API is not supported.

The chooser promise times out

Cause: the waiter was registered after the click, the click did not trigger a chooser, or another chooser remains unresolved. Fix: use Promise.all, cancel any prior chooser, and verify the page’s event path.

The upload appears to do nothing

Cause: the path is relative to an unexpected working directory, the file is absent in a container, or the page requires a separate submit action. Fix: resolve and check an absolute path, ensure the fixture exists where Chrome is running, then perform and await the site’s submit/upload request.

Remote execution cannot find a local file

Cause: the path exists only on the client machine. Fix: transfer or mount the file into the remote execution environment and pass that environment’s absolute path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Headful debugging shows no operating-system picker

Cause: Puppeteer intercepts the chooser programmatically. Fix: debug the page state and chooser promise rather than waiting for a visible native window.

Or skip the browser setup

If your goal is a rendered screenshot or PDF after an upload workflow—not interactive browser automation—ScreenshotNeo can return the capture through one HTTP request. Its cleanup steps accept cookie/consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. It also provides an MCP server for AI agents such as Claude and Cursor.

For a screenshot after your page is prepared, see the ScreenshotNeo API documentation and call:

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

ScreenshotNeo’s free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

API choices at a glance

Page behavior Puppeteer API Important detail
Traditional file input ElementHandle.uploadFile(...paths) Locate the input first; paths may be relative or absolute.
Button opens chooser page.waitForFileChooser() then fileChooser.accept(paths) Register the waiter before clicking.
Dismiss chooser fileChooser.cancel() Resolve the chooser so later dialogs are not blocked.
window.showOpenFilePicker Not supported by Puppeteer’s chooser interception Use an application/test design that exposes a supported input flow.

FAQ

Can I upload without clicking a visible file input?

Yes. If a traditional file input exists in the DOM, call uploadFile() directly; it does not require the operating-system picker to be visible.

Should I use a locator to upload files?

Puppeteer recommends locators for general interaction, while the documented file-upload workflow uses an element handle and uploadFile(). Use the API that supports the operation rather than trying to fill a file input as text.

Does Puppeteer validate that an uploaded path exists?

No. Check the file yourself before calling uploadFile() or accept(), especially in CI and remote-browser deployments.

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.

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