Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What's wrong on my file uploading? (Playwright)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading