Bird
0
0

Which of the following is the correct syntax to find a checkbox with the label 'Accept Terms' using cypress-testing-library?

easy📝 Syntax Q3 of 15
Cypress - Plugins and Ecosystem
Which of the following is the correct syntax to find a checkbox with the label 'Accept Terms' using cypress-testing-library?
Acy.findByRole('checkbox', { name: 'Accept Terms' })
Bcy.findByLabelText('checkbox', 'Accept Terms')
Ccy.findByText('Accept Terms').checkbox()
Dcy.get('checkbox').findByText('Accept Terms')
Step-by-Step Solution
Solution:
  1. Step 1: Understand role and name options

    findByRole accepts a role and an options object with name to match accessible name.
  2. Step 2: Why other syntaxes are invalid

    findByLabelText does not take role as first argument; chaining methods like .checkbox() don't exist; get('checkbox') is invalid selector.
  3. Final Answer:

    cy.findByRole('checkbox', { name: 'Accept Terms' }) -> Option A
  4. Quick Check:

    Use role with name option to find labeled checkbox [OK]
Quick Trick: Use role and name to find accessible elements precisely [OK]
Common Mistakes:
  • Passing label text as second argument to findByLabelText
  • Using invalid chaining methods
  • Using CSS selectors instead of roles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes