【问题标题】:Puppeteer FileChooser throwing "TypeError: undefined is not a function" ??? when trying to open the FileChooser to upload an IMGPuppeteer FileChooser 抛出“TypeError: undefined is not a function”???尝试打开 FileChooser 上传 IMG 时
【发布时间】:2020-05-26 01:05:55
【问题描述】:

我目前正在尝试使用 Puppeteer 上传图像,但是当我尝试打开 FileChooser 时:

你们都认识这个人 https://i.stack.imgur.com/aRApS.png 这是一个示例图片

要浏览并选择文件,我在控制台中收到以下错误

TypeError: undefined is not a function

然后是预期的超时错误

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

问题是……为什么是未定义的?我哪里出错了?这是我的代码:

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

在这之前的一切都很好

Puppeteer 版本:3.1.0

【问题讨论】:

    标签: node.js google-chrome automation puppeteer


    【解决方案1】:

    作为一种解决方法,我这样做并成功了:

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

    我更喜欢 fileChooser 语法,但似乎其他人的解决方法是降级 puppeteer 版本。我不想,所以我决定从上面走这条路。

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 2014-03-14
      • 2015-06-24
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      • 2015-01-14
      • 2014-07-06
      相关资源
      最近更新 更多