FileChooser
FileChooser objects are dispatched by the page in the page.on('filechooser') event.
// Note that Promise.all prevents a race condition
// between clicking and waiting for the file chooser.
const [fileChooser] = await Promise.all([
// It is important to call waitForEvent before click to set up waiting.
page.waitForEvent('filechooser'),
// Opens the file chooser.
page.getByText('Upload').click(),
]);
await fileChooser.setFiles('myfile.pdf');
- fileChooser.element()
- fileChooser.isMultiple()
- fileChooser.page()
- fileChooser.setFiles(files[, options])
fileChooser.element()
Added in: v1.8- returns:ElementHandle># <
Returns input element associated with this file chooser.
fileChooser.isMultiple()
Added in: v1.8Returns whether this file chooser accepts multiple files.
fileChooser.page()
Added in: v1.8Returns page this file chooser belongs to.
fileChooser.setFiles(files[, options])
Added in: v1.8files
<string|Array<string>|Object|Array<Object>>#options?
<Object>noWaitAfter?
<boolean> Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults tofalse
.#timeout?
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods.#
- returns:Promise<void>># <
Sets the value of the file input this chooser is associated with. If some of the filePaths
are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.