Skip to content

FileChooser ​

Added in: v1.8

FileChooser objects are dispatched by the page in the page.on("fileChooser") event.

python
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")
python
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")

Methods ​

file_chooser.element() ​

Added in: v1.8

Returns input element associated with this file chooser.

Returns

  • ElementHandle

file_chooser.is_multiple() ​

Added in: v1.8

Returns whether this file chooser accepts multiple files.

Returns

  • boolean

file_chooser.page() ​

Added in: v1.8

Returns page this file chooser belongs to.

Returns

  • Page

file_chooser.set_files() ​

Added in: v1.8

Sets 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.

Arguments

  • files path | Array<path> | Object | Array<Object>

    • name string

      File name

    • mime_type string

      File type

    • buffer Buffer

      File content

  • options Object (optional)

Released under the Apache 2.0 License.