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

I have used the code like this:await page.$$eval( 'input[name=name_check]', checks => chec

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743774992a4505060.html

相关推荐

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

    I have used the code like this:await page.$$eval( 'input[name=name_check]', checks => chec

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信