Nomad_Mio
Nomad_Mio

Reputation: 81

Puppeteer TimeoutError: Race Condition of FileChooser and Click

There seems to be a race condition between "waitForFileChooser" and "click" when I try to automate uploading files according to the puppeteer's documentation of API.

Sometimes it works, sometimes it doesn't, so how can I solve this issue?

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

const [fileChooser] = await Promise.all([
  page.waitForFileChooser(),
  page.click('#upload-file-button'), // a button that triggers file selection
]);
await fileChooser.accept(['someFile.pdf']);

Upvotes: 1

Views: 777

Answers (1)

lezhumain
lezhumain

Reputation: 405

You can increase the timeout for waitForFileChooser (see https://pub.dev/documentation/puppeteer/latest/puppeteer/Page/waitForFileChooser.html):

// ...
page.waitForFileChooser({timeout: 50000}),
// ...

Upvotes: 1

Related Questions