0

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:

  • codeceptjs: ^3.3.6,
  • playwright: ^1.19.0

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.

  • Expected: The uploaded file's name should be displayed
  • Actual: Nothing happens; no file name displayed; no error message returned in the logs
Newbie10
  • 99
  • 1
  • 14

1 Answers1

0

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.

jkalandarov
  • 564
  • 5
  • 15