'How to select and click a child div with Puppeteer
I am new to Puppeteer; trying to click on the first div after div with class version-cell create-update.
Not all web pages I scrape will have the version-cell create-update div, therefore need a conditional in code.
I am able to target the element with version-cell create-update but don't know how to target the correct version-cell div to click.
My HTML
<div class="jr-card jr-card-full-height">
<div class="jr-card-header d-flex mb-2"></div>
<div class="version-cell create-update"></div>
<div class="version-cell"></div>
<div class="version-cell"></div>
<div class="version-cell"></div>
<div class="version-cell"></div>
</div>
My code
const html = await page.content()
const $ = cheerio.load(html)
$(".version-cell").each((index, element) => {
if($(element).attr("class") === "version-cell create-update") {
$(".version-cell.create-update").next()
page.click(".version-cell")
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|