最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to check a checkbox using Puppeteer? - Stack Overflow

matteradmin3PV0评论

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?

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?

Share edited Mar 15, 2020 at 3:31 Grant Miller 29.1k16 gold badges156 silver badges170 bronze badges asked Feb 24, 2020 at 6:15 AshishAshish 831 silver badge8 bronze badges 1
  • 1 replace $$eval with $eval and checks will bee only one element matching the selector – mbit Commented Feb 24, 2020 at 6:32
Add a ment  | 

1 Answer 1

Reset to default 11

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);
Post a comment

comment list (0)

  1. No comments so far