Manuals / Playwright with Python / Chapter 16
Part 2 · Core Interactions · intermediate · ~35 min · Chapter 16 of 61
10. File Uploads & Downloads
# Single file page.get_by_label("Upload resume").set_input_files("resume.pdf") # Multiple files page.get_by_label("Attach files").set_input_files(["file1.png", "file2.png"]) # Clear a selected file page.get_by_label("Upload resume").set_input_files([]) This directly sets file(s) on an <input type="file"> element without touching the OS-level native file picker dialog at all. .set_input_files(paths
Step 1 of 2
Overview
This directly sets file(s) on an <input type="file"> element without touching the OS-level native file picker dialog at all. .set_input_files(paths) What it does: Sets file(s) on a file input element directly, bypassing the native OS file picker dialog. Types/params: Pointers: Works even on hidden file inputs (a styled "Upload" button triggering a hidden <input type="file">) — no OS-level automation needed. download = download_info.value As with new-tab handling, the with ... expect_download() pattern registers the listener before the triggering click.
- paths — one of:
- A single string path → uploads one file
- A list of string paths → uploads multiple files (if the input supports multiple)
- An empty list [] → clears the current selection
Try it
Run / study this snippet
# Single fileChapter learning outcomes
- # Single file page.get_by_label("Upload resume").set_input_files("resume.pdf") #
- .set_input_files(paths
Clear these before you leave
Side quest
10. File Uploads & Downloads deliverable
Apply one idea from “Overview” in a small script or note.