Puppeteer FileChooser throwing "TypeError: undefined is not a function" ??? when trying to open the FileChooser to upload an IMG

Viewed 664

I'm currently trying to upload an image using Puppeteer, however when I try to open the FileChooser:

Y'all know this guy https://i.stack.imgur.com/aRApS.png This is an example image

to browse and select a file, I get the following error in my console

TypeError: undefined is not a function

and then a timeout error which is expected

TimeoutError: waiting for waiting for file chooser failed: timeout 30000ms exceeded

The question would be... Why undefined? Where I went wrong? Here's my code:

const [fileChooser] = Promise.all([
  page.waitForFileChooser(),
  page.click("input#EventImage"),
]);
await fileChooser.accept([
  __dirname + "/screenshot.png",
]);

Everything else before this is working just fine

Puppeteer version: 3.1.0

1 Answers

As a workaround, I did this and succeeded:

await page.waitForSelector("selector");
const input = await page.$("selector");
await input.uploadFile(filepath);

I'd prefer the fileChooser syntax, but seems like the workaround for other people is to downgrade the puppeteer version. I did not wanted to, so I decided to take this path from above.

Related