Bird
0
0

You want to check multiple checkboxes with the same name attribute colors and values red and blue. Which code correctly checks both?

hard📝 Application Q8 of 15
Cypress - Element Interactions
You want to check multiple checkboxes with the same name attribute colors and values red and blue. Which code correctly checks both?
Acy.get('input[name="colors"]').check(['red', 'blue'])
Bcy.get('input[name="colors"]').check('red').check('blue')
Ccy.get('input[name="colors"]').check('red,blue')
Dcy.get('input[name="colors"]').uncheck(['red', 'blue'])
Step-by-Step Solution
Solution:
  1. Step 1: Understand checking multiple checkboxes

    To check multiple checkboxes with same name but different values, pass an array of values to check().

  2. Step 2: Analyze options

    cy.get('input[name="colors"]').check(['red', 'blue']) correctly uses check(['red', 'blue']). cy.get('input[name="colors"]').check('red').check('blue') calls check twice but chaining like that is less efficient. cy.get('input[name="colors"]').check('red,blue') passes a string with comma which is invalid. cy.get('input[name="colors"]').uncheck(['red', 'blue']) unchecks instead of checking.

  3. Final Answer:

    cy.get('input[name="colors"]').check(['red', 'blue']) -> Option A
  4. Quick Check:

    Use array of values to check multiple checkboxes [OK]
Quick Trick: Pass array of values to check() for multiple checkboxes [OK]
Common Mistakes:
  • Passing comma string instead of array
  • Using uncheck() instead of check()
  • Calling check() multiple times unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes