Newbie10
Newbie10

Reputation: 99

Nothing happens when using I.attachFile to upload a document

Is a drag-and-drop field required for the I.attachFile('element', 'filePath') to work? Because currently nothing happens when I try using the attachFile method. No error message or any issues displayed even when using --verbose.

This is the element where I try to attach my file //input[@type='file']. I also verified that I have the correct fileName and filePath since I tried using a wrong file name and it returned an error.

I am currently using:

I tried changing the file I'm about to upload to see if my file is the problem, but when I do upload the file manually in the page it works as expected; but when trying to do it in my code, nothing happens.

Upvotes: 0

Views: 337

Answers (1)

jkalandarov
jkalandarov

Reputation: 685

You can use setInputFiles method. Docs here

Example:

const input = await page.locator('//input[@type='file']');
await input.setInputFiles('./files/photos/myPhoto.jpeg'); // location of file

The file will be uploaded when you click on submit/send/upload button which will trigger the form submit event.

Upvotes: 0

Related Questions