admin管理员组文章数量:1394099
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
?
2 Answers
Reset to default 4You 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})
本文标签: javascriptPuppeteer TimeoutError waiting for selectorStack Overflow
版权声明:本文标题:javascript - Puppeteer: TimeoutError: waiting for selector - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744687027a2619764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论