mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
93e9acc410
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nikolay Vitkov <nvitkov@chromium.org>
74 lines
1.2 KiB
Markdown
74 lines
1.2 KiB
Markdown
---
|
|
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:
|
|
|
|
```typescript
|
|
class Page {
|
|
abstract waitForFileChooser(
|
|
options?: WaitTimeoutOptions
|
|
): Promise<FileChooser>;
|
|
}
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<table><thead><tr><th>
|
|
|
|
Parameter
|
|
|
|
</th><th>
|
|
|
|
Type
|
|
|
|
</th><th>
|
|
|
|
Description
|
|
|
|
</th></tr></thead>
|
|
<tbody><tr><td>
|
|
|
|
options
|
|
|
|
</td><td>
|
|
|
|
[WaitTimeoutOptions](./puppeteer.waittimeoutoptions.md)
|
|
|
|
</td><td>
|
|
|
|
_(Optional)_
|
|
|
|
</td></tr>
|
|
</tbody></table>
|
|
**Returns:**
|
|
|
|
Promise<[FileChooser](./puppeteer.filechooser.md)>
|
|
|
|
## 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.
|
|
|
|
```ts
|
|
const [fileChooser] = await Promise.all([
|
|
page.waitForFileChooser(),
|
|
page.click('#upload-file-button'),
|
|
// some button that triggers file selection
|
|
]);
|
|
await fileChooser.accept(['/tmp/myfile.pdf']);
|
|
```
|