I'm trying to iterate a list of objects that I have, and want to check if it has 'Add to Cart' text, then get it's productID and then break out of the loop (since I only want the first available item).
However, I've tried breaking it but it runs through all of the elements regardless, and can't seem it figure out why. Does it have to do with async await? I'm using puppeteer.
let putterID;
await putters.every(async (putter) => {
let inStock = await putter.$eval('.product-details .tocart a', el => el.innerHTML);
inStock = inStock.trim();
if (inStock == "Add To Cart") {
putterID = await putter.$eval('.product-details .price', el => el.getAttribute('data-publishproductid'));
console.log(`Found the first available putter with ID: ${putterID}`);
return false;
}
});