Bird
0
0

What does cy.findByRole('button') do in cypress-testing-library?

easy📝 Conceptual Q1 of 15
Cypress - Plugins and Ecosystem
What does cy.findByRole('button') do in cypress-testing-library?
AFinds elements by their CSS class named 'button'
BFinds any element with the text 'button'
CFinds all buttons on the page regardless of role
DFinds an element with the role attribute set to 'button'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role attribute in accessibility

    The role attribute defines the purpose of an element, like 'button' for clickable buttons.
  2. Step 2: How findByRole works in cypress-testing-library

    This command searches for elements with the specified ARIA role, ensuring accessibility compliance.
  3. Final Answer:

    Finds an element with the role attribute set to 'button' -> Option D
  4. Quick Check:

    Role-based element search = Finds element by role [OK]
Quick Trick: Use roles to find accessible elements easily [OK]
Common Mistakes:
  • Confusing role with text content
  • Assuming it finds by CSS class
  • Thinking it finds all buttons without role

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes