简体   繁体   English

上传文件后 puppeteer page.click() 卡住了

[英]puppeteer page.click() gets stuck after uploading a file

I'm uploading a file and then trying to click continue but it doesn't click on continue.我正在上传一个文件,然后尝试单击继续,但它没有单击继续。 Check the attached code snippet检查附加的代码片段

const elementHandle = await page.$("input[type=file]");
  await elementHandle.uploadFile(
    "E:/Learning/JavaScript/Projects/Automation/Downer/upload.docx"
  );

  await page.waitFor(300);
  await Promise.all([
    page.waitForNavigation(),
    await page.click("#saveContinue"),
  ]);
  await page.screenshot({ path: "example.png" });

If I'm commenting upload file code then it does click on the continue so it's working without upload file but not working with upload file code.如果我正在评论上传文件代码,那么它确实会点击继续,因此它可以在没有上传文件的情况下工作,但不能使用上传文件代码。 I've also tried it outside of the Promise.all and It kinda gets stuck neither it throws an error nor clicks on the continue.我也在 Promise.all 之外尝试过它,它有点卡住了,既没有抛出错误也没有点击继续。

Basing on this it appears that puppeteer expects relative path (official docs are not clear in this matter, though).基于,puppeteer 似乎期望相对路径(尽管官方文档在这方面并不清楚)。 Have you tried specifying path relatively to cwd?您是否尝试过指定相对于 cwd 的路径?

So, assuming your script is in E:/Learning/JavaScript/Projects/Automation/Downer :因此,假设您的脚本位于E:/Learning/JavaScript/Projects/Automation/Downer中:

const filePath = path.relative(process.cwd(), __dirname + '/upload.docx');
const input = await page.$('input[type=file]');
await input.uploadFile(filePath);

And, by the way - without upload code it works - but without await for input and the upload itself, or only without the uploadFile?而且,顺便说一句 -没有上传代码它可以工作- 但没有等待input和上传本身,或者只是没有 uploadFile?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM