FileChooser
FileChooser 对象通过 page.on("filechooser") 事件派发。
- Sync
- Async
with page.expect_file_chooser() as fc_info:
page.get_by_text("Upload").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").click()
file_chooser = await fc_info.value
await file_chooser.set_files("myfile.pdf")
- file_chooser.element
- file_chooser.is_multiple()
- file_chooser.page
- file_chooser.set_files(files, **kwargs)
file_chooser.element
Added in: v1.8- 返回值: <ElementHandle>#
返回与该 FileChooser 关联的 <input type=file> 元素。
file_chooser.is_multiple()
Added in: v1.8指示该文件选择器是否允许多选。
file_chooser.page
Added in: v1.8返回所属的 Page。
file_chooser.set_files(files, **kwargs)
Added in: v1.8files<Union[str, pathlib.Path]|List[Union[str, pathlib.Path]]|Dict|List[Dict]>#no_wait_after<bool> 是否跳过因该操作触发导航时的等待,默认false。仅在导航指向不可访问页面等少数场景需要设置。#timeout<float> 超时时间(毫秒),默认 30 秒,传0表示无限制,可通过 browser_context.set_default_timeout(timeout) 或 page.set_default_timeout(timeout) 修改默认值。#- 返回值: <NoneType>#
设置文件输入的值。若 files 中包含相对路径,将基于当前工作目录解析。传入空数组可清空选中的文件。