← Back to library
Playwrightfilebeginnerv1.20+

Upload a file

Trigger a file input and upload a local file.

1test('uploads a file', async ({ page }) => {
2  await page.goto('/upload');
3
4  // Set the file directly on the input — no dialog needed
5  await page.locator('input[type="file"]').setInputFiles('tests/fixtures/sample.pdf');
6
7  await page.getByRole('button', { name: 'Submit' }).click();
8  await expect(page.getByText('Upload successful')).toBeVisible();
9});
#upload#file#input