FileChooser
Added in: v1.8FileChooser objects are dispatched by the page in the page.on('fileChooser') event.
// Start waiting for file chooser before clicking. Note no await.
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByText('Upload file').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));Methods
fileChooser.element()
Added in: v1.8Returns input element associated with this file chooser.
Returns
ElementHandle
fileChooser.isMultiple()
Added in: v1.8Returns whether this file chooser accepts multiple files.
Returns
boolean
fileChooser.page()
Added in: v1.8Returns page this file chooser belongs to.
Returns
Page
fileChooser.setFiles()
Added in: v1.8 asyncSets 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.
Arguments
filespath | Array<path> | Object | Array<Object>namestringFile name
mimeTypestringFile type
bufferBufferFile content
noWaitAfterboolean(optional)This option has no effect.
signalAbortSignal(optional) Added in: v1.62Allows to cancel the operation using an
AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed usingbrowserContext.setDefaultTimeout()orpage.setDefaultTimeout(); passtimeout: 0to disable the timeout entirely.Maximum time in milliseconds. Defaults to
0- no timeout. The default value can be changed viaactionTimeoutoption in the config, or by using thebrowserContext.setDefaultTimeout()orpage.setDefaultTimeout()methods.