FileChooser
FileChooser 对象由页面通过 page.on('filechooser') 事件分发。
// 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返回与此文件选择器关联的输入元素。
🌐 Returns input element associated with this file chooser.
用法
fileChooser.element();
返回
isMultiple
Added before v1.9返回此文件选择器是否接受多个文件。
🌐 Returns whether this file chooser accepts multiple files.
用法
fileChooser.isMultiple();
返回
page
Added before v1.9返回此文件选择器所属的页面。
🌐 Returns page this file chooser belongs to.
用法
fileChooser.page();
返回
setFiles
Added before v1.9设置此选择器关联的文件输入的值。如果某些 filePaths 是相对路径,则它们相对于当前工作目录解析。对于空数组,会清除所选文件。
🌐 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.
用法
await fileChooser.setFiles(files);
await fileChooser.setFiles(files, options);
参数
-
optionsObject (optional)-
noWaitAfterboolean (optional)#:::警告[已弃用] 这个选项没有效果。 :::
此选项无效。
-
最大时间(毫秒)。默认为
0- 无超时。默认值可以通过配置中的actionTimeout选项更改,或者使用 browserContext.setDefaultTimeout() 或 page.setDefaultTimeout() 方法更改。
-
返回