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})