0
0
Cypresstesting~20 mins

cy.select() for dropdowns in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dropdown Mastery with cy.select()
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the result of this Cypress test code?
Consider the following Cypress test code that selects an option from a dropdown menu. What will be the test execution result?
Cypress
cy.get('#fruits').select('Banana').should('have.value', 'banana')
ATest passes because the option 'Banana' exists and its value is 'banana'.
BTest fails because the selector '#fruits' is invalid.
CTest fails because 'Banana' is not a valid option in the dropdown.
DTest fails due to syntax error in the select command.
Attempts:
2 left
💡 Hint
Check if the option text matches the value used in the assertion.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the selected option in a dropdown?
You want to verify that the dropdown with id 'colors' has 'Red' selected after using cy.select(). Which assertion is correct?
Cypress
cy.get('#colors').select('Red')
Acy.get('#colors').should('have.value', 'red')
Bcy.get('#colors').should('contain', 'Red')
Ccy.get('#colors').should('have.text', 'Red')
Dcy.get('#colors').should('be.visible')
Attempts:
2 left
💡 Hint
The selected option's value attribute is used for verification.
locator
advanced
2:00remaining
Identify the best locator for selecting a dropdown in Cypress
Which locator is the best practice to select a dropdown with label 'Country' for accessibility and reliability?
Acy.get('#country-dropdown')
Bcy.get('select').eq(0)
Ccy.get('select').contains('Country')
Dcy.get('select[aria-label="Country"]')
Attempts:
2 left
💡 Hint
Use locators that rely on accessibility attributes for stability.
🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail when selecting a dropdown option?
Given this code, why does the test fail? cy.get('#pets').select('Dog').should('have.value', 'dog')
Cypress
<select id="pets">
  <option value="cat">Cat</option>
  <option value="doggo">Dog</option>
  <option value="bird">Bird</option>
</select>
AThe selector '#pets' is incorrect and does not find the dropdown.
BThe assertion uses 'dog' but the option's value is 'doggo', causing failure.
CThe select command syntax is invalid and causes a runtime error.
DThe option text 'Dog' does not match any option's value attribute 'doggo'.
Attempts:
2 left
💡 Hint
Check the value attribute of the option you want to select.
framework
expert
3:00remaining
How to handle dynamic dropdown options in Cypress tests?
You have a dropdown whose options load dynamically after an API call. Which approach ensures your Cypress test selects the option 'Option 3' reliably?
ASelect the option immediately after page load without waiting.
BUse cy.wait() with a fixed time before selecting the option.
CUse cy.intercept() to wait for the API call, then select the option.
DUse cy.get() with {timeout: 0} to select the option instantly.
Attempts:
2 left
💡 Hint
Wait for the network response that loads the dropdown options.