简体   繁体   中英

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

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:)

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM