FileChooser
FileChooser objects are dispatched by the page in the page.on("filechooser") event.
- Sync
- Async
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")
方法 (Methods)
set_files
Added before v1.9Sets 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.
使用方式
file_chooser.set_files(files)
file_chooser.set_files(files, **kwargs)
參數
-
files
Union[str, pathlib.Path] | List[Union[str, pathlib.Path]] | Dict | List[Dict]# -
no_wait_after
bool (optional)#DeprecatedThis option has no effect.
This option has no effect.
-
Maximum time in milliseconds. Defaults to
30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the browser_context.set_default_timeout() or page.set_default_timeout() methods.
傳回值
屬性 (Properties)
element
Added before v1.9Returns input element associated with this file chooser.
使用方式
file_chooser.element
傳回值
is_multiple
Added before v1.9Returns whether this file chooser accepts multiple files.
使用方式
file_chooser.is_multiple()
傳回值
page
Added before v1.9Returns page this file chooser belongs to.
使用方式
file_chooser.page
傳回值