I am trying to loop through an array to search and add multiple items in cart in https://www.woolworths.com.au/shop/search/ However, after the search the add to cart button simply does not work from Puppetteer. I have tried several ways like using xpath, text, classname and none of them seem to work.
const [button] = await page.$x("//button[contains(., ' Add to cart ')]");
if (button) {
await button.click();
}
const buttons = await page.$$('button[class*="cartControls-addButton"]')
.then(()=>console.log("got buttons"))
console.log(buttons);
await buttons[i].click();
let button = await page.$x('//*[@id="search-content"]/div/wow-product-search-container/shared-grid/div/div[1]/shared-product-tile/section/footer/div/shared-cart-controls/div/shared-cart-buttons/div/div/div/div/button/span')
console.log(button);
const linkHandlers = await page.$x("//a[contains(text(), ' Add to cart ')]");
if (linkHandlers.length > 0) {
await linkHandlers[0].click();
} else {
throw new Error("Link not found");
}
Can you please let me know what my issue is? I also have all of my code in this repo .