puppeteer/docs/api/puppeteer.page.waitforfilechooser.md
Alex Rudenko df4d60c187
feat!: switch to Chrome for Testing instead of Chromium (#10054)
Co-authored-by: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com>
2023-05-02 08:53:40 +02:00

1.2 KiB

sidebar_label
Page.waitForFileChooser

Page.waitForFileChooser() method

This method is typically coupled with an action that triggers file choosing.

:::caution

This must be called before the file chooser is launched. It will not return a currently active file chooser.

:::

Signature:

class Page {
  waitForFileChooser(options?: WaitTimeoutOptions): Promise<FileChooser>;
}

Parameters

Parameter Type Description
options WaitTimeoutOptions (Optional)

Returns:

Promise<FileChooser>

Remarks

In the "headful" browser, this method results in the native file picker dialog not showing up for the user.

Example

The following example clicks a button that issues a file chooser and then responds with /tmp/myfile.pdf as if a user has selected this file.

const [fileChooser] = await Promise.all([
  page.waitForFileChooser(),
  page.click('#upload-file-button'),
  // some button that triggers file selection
]);
await fileChooser.accept(['/tmp/myfile.pdf']);