【问题标题】:Puppeteer is failing to upload a file with TypeError: Failed to fetchPuppeteer 无法上传带有 TypeError: Failed to fetch 的文件
【发布时间】:2020-07-03 10:50:12
【问题描述】:

我已经关注了有关如何使用 Puppeteer 的 uploadFile() 方法的文档和示例。

但是,我不断收到此错误消息Evaluation failed: TypeError: Failed to fetch

我不知道为什么我不能自动上传。我有一个保存在我的仓库中的文件,我正在尝试上传。

这是uploadFile() 代码的sn-p。

    await page.waitForSelector('input[type="file"]');


    const fileInput = await page.$('input[type="file"]');

    const filePath = 'path-to-my-file';

    await fileInput.uploadFile(filePath);

关于我应该看哪里的任何指针?

* “解决方案” * 看起来 Puppeteer 版本 2.1.1 可能存在此 GitHub 票证指示的问题。 https://github.com/puppeteer/puppeteer/issues/5503 如果您检查 repo(截至 2020 年 3 月 23 日),还有其他几个与同一问题相关的未决票证。

在该票证中,用户降级到 2.0.0 并且附件功能正常工作。

【问题讨论】:

  • 确保正确解析路径。在脚本顶部添加const Path = require('path');,然后在脚本中添加const filePath = Path.join(__dirname, 'path-to-file-relative-to-this-script.jpg');。这个对我有用。如果您使用的是 Unix,请确保该文件具有访问权限
  • @blex 刚刚尝试过,但我仍然收到Evaluation failed: TypeError: Failed to fetch 错误。

标签: javascript google-chrome testing jestjs puppeteer


【解决方案1】:

看起来 Puppeteer 版本 2.1.1 可能存在此 GitHub 票证指出的问题。 https://github.com/puppeteer/puppeteer/issues/5503

在该票证中,用户降级到 2.0.0 并且附件功能正常工作。

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 1970-01-01
    • 2018-04-03
    • 2020-07-10
    • 2020-09-18
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多