木偶器文件选择器投掷"TypeError: undefined is not a function" ???尝试打开文件选择器以上传 IMG 时



我目前正在尝试使用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",
]);

在此之前的其他一切都工作正常

木偶师版本:3.1.0

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

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

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

最新更新