I need to choose опе book without a sale. On the page, I have 9 products, and some of them have the class hasDiscount.
I need to choose the first product without the class hasDiscount. But: I need to click on the button Buy, because if I click on all products, I can't add them to the basket.
My code:
for(const row of await page.locator('.note-item.card.h-100').all())
{
if (row.not.toHaveClass('hasDiscount'))
{
await page.locator('.actionBuyProduct').first().click()
}
}
In the first row of my code, I choose all 9 products, and if one of them doesn't have the class hasDiscount, then I click on the button "Buy".
But my code doesn't work. What is wrong with it?
How can I fix it?


.all()will not auto wait, and will return an empty array, so the loop won't run. If there ARE elements, then you should see a crash, because.not.toHaveClasslooks made up. Thanks.