I use a module called Puppeteer.
I tried waiting for a selector on my page that may not appear. Out of the two approaches I took, only the try-catch method worked.
try-catch block - working
try {
await page.waitForSelector('.element');
//element appeared
} catch (error) {
//element did not appear
}
promise chaining - not working
await page.waitForSelector('.element')
.catch((error) => {
//element did not appear
})
.then(() => {
//element appeared
});
It seems that waitForSelector does return a Promise as indicated in the API, but I can't figure why the latter approach didn't work. It threw the error anyway.
Have anyone encountered the same issue?