How to check a checkbox using Puppeteer?

Issue

I have used the code like this:

await page.$$eval( 'input[name=name_check]', checks => checks.forEach(c => c.checked = true)

But this is for multiple checkboxes. I want to use this for a single checkbox.

How can I check only one checkbox?

Solution

page.$eval()

You can use page.$eval() instead of page.$$eval() to check one checkbox instead of multiple checkboxes:

await page.$eval('input[name="name_check"]', check => check.checked = true);

Answered By – Grant Miller

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.