I’m facing with an issue that my files are not being uploaded to website, here is a code:
await mainPage.clickElement('locator for the element "Add logo"');
page.on('filechooser', async (fileChooser) => {
await fileChooser.setFiles('path to jpg file');
});
I’m using "@playwright/test": "^1.19.2",
why it is not working, what’s wrong?
Here is a DOM:
https://i.stack.imgur.com/73Q48.png
UPD:
await mainPage.clickElement('locator for the element "Add logo"');
is a simple page.click(), just used from PageObject
>Solution :
You are having a race condition. I recommend using the waitForEvent function instead:
const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.click('locator for the element "Add logo"'),
]);
await fileChooser.setFiles('path to jpg file');