O hirunewani blog

Playwrightでファイル選択をする

Created at

PlaywrightでFileChooserオブジェクトを利用してファイル選択をエミュレートする方法について紹介する。

PlaywrightはFileChooserオブジェクトを利用すると、ファイル選択をエミュレートできる。

https://playwright.dev/docs/api/class-filechooser

const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByText("Upload file").click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, "myfile.pdf"));