javascript - Puppeteer: TimeoutError: waiting for selector - Stack Overflow

I am waiting for a selector to load on the page but I also need to handle cases where there is a timeou

I am waiting for a selector to load on the page but I also need to handle cases where there is a timeout.

Currently, my script stops execution and does not continue. How can i handle error cases of timeout and still proceed with execution.

below is my relevant code.

    const newPagePromise = new Promise(res => browser.on('targetcreated', target => res(target.page())));
    for(const dataWorkSheet of dataWorkSheetsArray) {
       try{
         await page.evaluate(async () => {
          await $('.export--popup a').click();
         });
         const exportPopup = await newPagePromise;
         await Promise.all([
          await exportPopup.click('#data-0'),
          await exportPopup.waitForSelector('.cLink'),
         ]);
       } catch(e) {

       }
    }

How can i ensure, my loop continues even when there is a timeout error when executing waitForSelector?

I am waiting for a selector to load on the page but I also need to handle cases where there is a timeout.

Currently, my script stops execution and does not continue. How can i handle error cases of timeout and still proceed with execution.

below is my relevant code.

    const newPagePromise = new Promise(res => browser.on('targetcreated', target => res(target.page())));
    for(const dataWorkSheet of dataWorkSheetsArray) {
       try{
         await page.evaluate(async () => {
          await $('.export--popup a').click();
         });
         const exportPopup = await newPagePromise;
         await Promise.all([
          await exportPopup.click('#data-0'),
          await exportPopup.waitForSelector('.cLink'),
         ]);
       } catch(e) {

       }
    }

How can i ensure, my loop continues even when there is a timeout error when executing waitForSelector?

Share Improve this question asked Jun 23, 2020 at 14:24 opensource-developeropensource-developer 3,0786 gold badges48 silver badges109 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You could play with the catch of the promise:

await Promise.all([
  await exportPopup.click('#data-0'),
  await exportPopup.waitForSelector('.cLink').catch(error => console.log('failed to wait 
 for the selector'),
 ]);

Maybe you can considering add some more time to wait the element so that the script will continue to run?

await exportPopup.waitForSelector('.cLink', {timeout: 120000})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744687028a4587981.html

相关推荐

  • javascript - Puppeteer: TimeoutError: waiting for selector - Stack Overflow

    I am waiting for a selector to load on the page but I also need to handle cases where there is a timeou

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信