'Puppeteer Scrolling And Clicking Selectiors with Same Class names
I'm quiet new to Puppeteer and NodeJs, so im trying to scrape a certain website where there are multiple posts that has this List element on clicking on it the comment section loads now my Qyestion Is: I want to click all the list elements(since they all have same class name), I can click on one of them by running the following code, now I want to scroll the page step by step and click on all of them respectively. Any help will be appreciated, and if anyone can guide me to a certain page or a video link that can help me that will be really helpfull. Cudos!!
await page.click('li.social-details-social-counts__comments.social-details-social-counts__item.social-details-social-counts__item--with-social-proof');`
Solution 1:[1]
You need to use page.$$ which is the same as querySelectorAll. And then in the loop click on each of these elements.
const links = await page.$$(
"li.social-details-social-counts__comments.social-details-social-counts__item.social-details-social-counts__item--with-social-proof"
);
for (let i = 0; i < links.length; i++) {
await page.click(links[i]);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mikhail Zub |