Playwright + Python · Lesson 23 of 37
Module 23: File Handling
Your task
Implement upload_document(page, selector, file_path):
Write it in the editor, then press Check answer (Ctrl + Enter).
from pathlib import Path
page.locator("input[type='file']").set_input_files("test_data/report.pdf")
with page.expect_download() as download_info:
page.get_by_role("button", name="Export CSV").click()
download = download_info.value
download.save_as(Path("downloads") / download.suggested_filename)Uploading avatars and verifying downloaded reports are essential workflows. In this lesson, you will master set_input_files and expect_download() in Python. Let's handle files!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Yes! Pass a list of file paths: set_input_files(['file1.png', 'file2.png']).
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___