I am looking for a way to check if an element exists on a page. If it does not exist, I want to look for an other element.
Example:
I want to find the h1
on a page.
If it does not exist I want to look for an h2
.
I am looking for a way to check if an element exists on a page. If it does not exist, I want to look for an other element.
Example:
I want to find the h1
on a page.
If it does not exist I want to look for an h2
.
This works for me:
if (await page.$(‘h1‘) !== null) {
console.log(‘Found a h1 element‘)
}
else if (await page.$(‘h2‘) !== null) {
console.log(‘Found a h2 element‘)
}
Here is the link to the solution: https://github.com/puppeteer/puppeteer/issues/1149