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.9Returns input element associated with this file chooser.
使用方式
fileChooser.element();
傳回值
isMultiple
Added before v1.9Returns whether this file chooser accepts multiple files.
使用方式
fileChooser.isMultiple();
傳回值
page
Added before v1.9Returns page this file chooser belongs to.
使用方式
fileChooser.page();
傳回值
setFiles
Added before v1.9Sets 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.
使用方式
await fileChooser.setFiles(files);
await fileChooser.setFiles(files, options);
參數
files
string | Array<string> | Object | Array<Object>#options
Object (optional)-
noWaitAfter
boolean (optional)#DeprecatedThis option has no effect.
This option has no effect.
-
Maximum time in milliseconds. Defaults to
0
- no timeout. The default value can be changed viaactionTimeout
option in the config, or by using the browserContext.setDefaultTimeout() or page.setDefaultTimeout() methods.
-
傳回值