How to quickly find out if an element exists in a page or not using playwright

Solution 1:

You can use those options then

const element = await page.$$("text='element'");
if (element) {
    // ...
}

or

const element = await page.$$("text='element'");
if (element.length) {
    // ...
}

or

await expect(page.locator(".MyClass")).toHaveCount(0)