If you use await
you can just use try...catch
. No need for .then
or .catch
... that's the whole point of using await
in the first place.
const check = async () => {
try {
return await page.waitForSelector(els.configurationBtn) != null;
} catch {
return false;
}
}
Or just use .then
and pass a second argument to it. The second function is called when the promise is rejected.
const check = () => page.waitForSelector(els.configurationBtn)
.then(res => res != null, () => false);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…