How can I check if a div has a certain class using puppeteer?

Viewed 324
if (await page.$("has-cart")) {

const page2 = await browser.newPage();        
await page2.goto('https://www.supremenewyork.com/checkout');       
await page2.bringToFront();
}

else console.log('not found');

this is supposed to check if the DOM has the class "has-cart" in it then do the function but it isn't working. Plz give suggestions if possible :)

1 Answers

you missed a dot inside your selector page.$(".has-cart") should work. With page.$('has-cart) you would match elements with this name ->

<has-cart>..</has-cart>

With .has-cart you get any element wich contain this class

<div class="has-cart">...</div>
Related