I can't figure out why this piece of code not working:
var stock; var stockEL = await page.$eval('.qty tbody tr td:nth-of-type(1) span'); if ( stockEL !== null) { stock = stockEL.getAttribute('data-tip'); } I am trying to use in Puppeteer. I would like to check if a span of first td exists, if yes, read the span attribute, if not exists do nothing.
Error: Error: failed to find element matching selector ".qty tbody tr td:nth-of-type(1) span"
"div"? Basically, I am trying to determine if the page is being loaded at all, or if it is being loaded, but the selector just doesn't exist on the loaded page.page.$eval()needs a function as its second argument, so maybe you meantpage.$()to get ElementHandle; 2. ElementHandle has nogetAttributemethod — it is not a DOM element. See the difference: stackoverflow.com/questions/55017057/… and stackoverflow.com/questions/55388455/…