Playwright + Java · Lesson 24 of 38
Module 24: File Handling
Your task
Implement uploadDocument:
Write it in the editor, then press Check answer (Ctrl + Enter).
import java.nio.file.Paths;
page.locator("input[type='file']").setInputFiles(Paths.get("test-data/invoice.pdf"));
Download download = page.waitForDownload(() -> {
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Export CSV")).click();
});
download.saveAs(Paths.get("downloads/" + download.suggestedFilename()));Uploading profile pictures and downloading monthly statement PDFs are essential enterprise workflows. In this lesson, you will master setInputFiles and Playwright's Download event listener to inspect downloaded files. Let's automate files!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Yes, pass an array of Paths: setInputFiles(new Path[]{ path1, path2 }).
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___