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'));
方法
element
在 v1.9 版本之前添加返回与此文件选择器关联的 input 元素。
用法
fileChooser.element();
返回
isMultiple
在 v1.9 版本之前添加返回此文件选择器是否接受多个文件。
用法
fileChooser.isMultiple();
返回
page
在 v1.9 版本之前添加返回此文件选择器所属的页面。
用法
fileChooser.page();
返回
setFiles
在 v1.9 版本之前添加设置此选择器关联的文件输入的值。如果某些 filePaths
是相对路径,则它们相对于当前工作目录解析。对于空数组,清除选定的文件。
用法
await fileChooser.setFiles(files);
await fileChooser.setFiles(files, options);
参数
files
string | Array<string> | Object | Array<Object>#options
Object (可选)-
已弃用
此选项无效。
此选项无效。
-
最大等待时间,单位为毫秒。默认为
0
- 无超时。默认值可以通过配置中的actionTimeout
选项更改,或者使用 browserContext.setDefaultTimeout() 或 page.setDefaultTimeout() 方法。
-
返回