I am unable to upload a file using Playwright as it can’t find a locator for input type
I’m trying to upload a file as below :
await page.locator('//div/input[@class=xyz]').setInputFiles('Upload_files/CSV Test file.csv');
but the browser is unable to find this locator as the input type as attribute hidden
<input type="file" class="xyz" accept=".jpg,.jpeg,.png,.doc,.docx,.xlsx,.xls,.csv,.pdf" hidden>
2
Answers
Not sure I really like this, but you could remove the hidden attribute first…
I have had luck finally figured this out:
You don’t try to find the input. You try to wait for the file chooser to show.
I have a button#browse that triggers the hidden file input. So this is the code that worked for me:
Got this from another reply here in stackoverflow: Playwright: Upload files from non-input element that cannot be used page.setInputFiles?