33文字
1分
編集

Playwrightでファイル選択をする

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

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

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