跳到主要内容

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 版本之前添加 fileChooser.element

返回与此文件选择器关联的 input 元素。

用法

fileChooser.element();

返回


isMultiple

在 v1.9 版本之前添加 fileChooser.isMultiple

返回此文件选择器是否接受多个文件。

用法

fileChooser.isMultiple();

返回


page

在 v1.9 版本之前添加 fileChooser.page

返回此文件选择器所属的页面。

用法

fileChooser.page();

返回


setFiles

在 v1.9 版本之前添加 fileChooser.setFiles

设置此选择器关联的文件输入的值。如果某些 filePaths 是相对路径,则它们相对于当前工作目录解析。对于空数组,清除选定的文件。

用法

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

参数

返回