Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
Cypress - Element Interactions
Consider this code:
cy.get('select').select('Banana').should('have.text', 'Banana')

What will happen when this test runs?
AThe test passes if the selected option's visible text is 'Banana'
BThe test passes regardless of the selected option
CThe test fails because 'have.text' is not valid for select elements
DThe test throws a runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the assertion target

    The have.text assertion checks the text content of the element, but a select element's text includes all options, not just the selected one.
  2. Step 2: Why the test fails

    To check the selected option's text, the correct assertion is to check the value or use find('option:selected'). Using have.text on select is invalid here.
  3. Final Answer:

    The test fails because 'have.text' is not valid for select elements -> Option C
  4. Quick Check:

    Use correct assertion for selected option text [OK]
Quick Trick: Use 'have.value' or check selected option, not 'have.text' on select [OK]
Common Mistakes:
  • Using 'have.text' on select element
  • Assuming select text equals selected option text
  • Ignoring correct assertion methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes