2

I'm trying to use puppeteer for click on 3 div, but they have the same class.

page.click('.not-selected-1Tb33').then(async () => {
    await page.click('.list-item-MOAq4')
})

Puppeteer clicks on the first that it find, but I want to click also on the second and the third that have the same class name.
How I can do?
Thanks in advance and sorry for bad english!

BlackdestinyXX
  • 331
  • 3
  • 17
  • it always clicks only first element, so try selecting them all, and then loop through each, see here: https://stackoverflow.com/questions/48673906/collect-elements-by-class-name-and-then-click-each-one-puppeteer – traynor Dec 28 '21 at 15:38

1 Answers1

1

Use for ... of:

const buttons = await page.$$(selector)
for (let btn of buttons) {
   await btn.click()
}
Josep Alsina
  • 2,762
  • 1
  • 16
  • 12