Skip to main content

FileChooser

FileChooser 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

element

Added before v1.9 fileChooser.element

Returns input element associated with this file chooser.

Usage

fileChooser.element();

Returns


isMultiple

Added before v1.9 fileChooser.isMultiple

Returns whether this file chooser accepts multiple files.

Usage

fileChooser.isMultiple();

Returns


page

Added before v1.9 fileChooser.page

Returns page this file chooser belongs to.

Usage

fileChooser.page();

Returns


setFiles

Added before v1.9 fileChooser.setFiles

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.

Usage

await fileChooser.setFiles(files);
await fileChooser.setFiles(files, options);

Arguments

Returns