FileChooser
FileChooser 对象会在页面的 page.on("filechooser") 事件中被分发。
- 同步
- 异步
with page.expect_file_chooser() as fc_info:
page.get_by_text("Upload file").click()
file_chooser = fc_info.value
file_chooser.set_files("myfile.pdf")
async with page.expect_file_chooser() as fc_info:
await page.get_by_text("Upload file").click()
file_chooser = await fc_info.value
await file_chooser.set_files("myfile.pdf")
方法
set_files
v1.9 之前添加设置此文件选择器关联的文件输入的值。如果 filePaths
中有相对路径,则会相对于当前工作目录进行解析。传入空数组时,会清除已选择的文件。
用法
file_chooser.set_files(files)
file_chooser.set_files(files, **kwargs)
参数
-
files
Union[str, pathlib.Path] | List[Union[str, pathlib.Path]] | Dict | List[Dict]# -
已废弃
此选项无效。
此选项无效。
-
超时时间(毫秒)。默认为
30000
(30 秒)。传入0
可禁用超时。默认值可通过 browser_context.set_default_timeout() 或 page.set_default_timeout() 方法进行更改。
返回值
属性
element
v1.9 之前添加返回与此文件选择器关联的 input 元素。
用法
file_chooser.element
返回值
is_multiple
v1.9 之前添加返回此文件选择器是否支持多文件选择。
用法
file_chooser.is_multiple()
返回值
page
v1.9 之前添加返回此文件选择器所属的页面。
用法
file_chooser.page
返回值