Bird
Raised Fist0
Cypresstesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the cy.select() command do in Cypress testing?
easy
A. It types text into an input field.
B. It selects an option from a dropdown menu.
C. It clicks a button on the page.
D. It waits for an element to appear.

Solution

  1. Step 1: Understand the purpose of cy.select()

    The cy.select() command is designed specifically to choose options from dropdown menus in Cypress tests.
  2. Step 2: Compare with other commands

    Typing text uses cy.type(), clicking uses cy.click(), and waiting uses cy.wait(). So, cy.select() is unique for dropdowns.
  3. Final Answer:

    It selects an option from a dropdown menu. -> Option B
  4. Quick Check:

    cy.select() = picks dropdown option [OK]
Hint: Remember: select = pick dropdown option [OK]
Common Mistakes:
  • Confusing cy.select() with cy.type()
  • Using cy.select() on non-dropdown elements
  • Thinking cy.select() clicks buttons
2. Which of the following is the correct syntax to select an option by its visible text using cy.select()?
easy
A. cy.get('select').select('Option Text')
B. cy.get('select').selectByText('Option Text')
C. cy.select('select', 'Option Text')
D. cy.get('select').choose('Option Text')

Solution

  1. Step 1: Recall the correct cy.select() syntax

    The correct way is to first get the dropdown element with cy.get(), then call .select() with the visible text as argument.
  2. Step 2: Eliminate incorrect methods

    There is no selectByText() or choose() method in Cypress. Also, cy.select() is not called directly with selector and text.
  3. Final Answer:

    cy.get('select').select('Option Text') -> Option A
  4. Quick Check:

    Use cy.get().select(text) syntax [OK]
Hint: Always use cy.get(selector).select(value) [OK]
Common Mistakes:
  • Using non-existent methods like selectByText()
  • Calling cy.select() without cy.get()
  • Using choose() instead of select()
3. What will be the result of this Cypress code snippet?
cy.get('#colors').select('blue').should('have.value', 'blue')
medium
A. The test will fail because 'blue' is not a valid value.
B. The dropdown will select the option with visible text 'blue' but the assertion will fail.
C. The code will throw a syntax error because of missing quotes.
D. The dropdown with id 'colors' will select the option with value 'blue' and the test will pass.

Solution

  1. Step 1: Understand the select and assertion

    The code selects the option with visible text or value 'blue' from the dropdown with id 'colors'. Then it asserts the dropdown's value is 'blue'.
  2. Step 2: Check for syntax and logic

    The syntax is correct with quotes. If 'blue' is a valid option value, the assertion will pass.
  3. Final Answer:

    The dropdown with id 'colors' will select the option with value 'blue' and the test will pass. -> Option D
  4. Quick Check:

    Select + assert value = pass if value exists [OK]
Hint: Select then assert value to confirm selection [OK]
Common Mistakes:
  • Assuming visible text and value differ without checking
  • Missing quotes causing syntax errors
  • Ignoring assertion failure possibility
4. Identify the error in this Cypress test code:
cy.get('select#country').select(2).should('have.value', 'US')
medium
A. Using a number 2 to select by index is invalid in cy.select().
B. The selector 'select#country' is incorrect syntax.
C. The assertion should use 'have.text' instead of 'have.value'.
D. The select command must be chained after should(), not before.

Solution

  1. Step 1: Check the use of select argument

    In Cypress, cy.select() accepts visible text, value, or an array of these. Selecting by index number directly (like 2) is not supported.
  2. Step 2: Verify selector and assertion

    The selector select#country is valid CSS. The assertion should('have.value', 'US') is correct to check the selected value.
  3. Final Answer:

    Using a number 2 to select by index is invalid in cy.select(). -> Option A
  4. Quick Check:

    cy.select() does not accept index number [OK]
Hint: Select by text or value, not index number [OK]
Common Mistakes:
  • Trying to select by index number directly
  • Confusing have.value with have.text
  • Incorrect chaining order of commands
5. You want to select multiple options from a multi-select dropdown with id 'fruits'. Which is the correct way to select 'Apple' and 'Banana' using cy.select()?
hard
A. cy.get('#fruits').select('Apple').select('Banana').should('have.value', ['Apple', 'Banana'])
B. cy.get('#fruits').select('Apple, Banana').should('have.value', 'Apple, Banana')
C. cy.get('#fruits').select(['Apple', 'Banana']).should('have.value', ['Apple', 'Banana'])
D. cy.get('#fruits').select('Apple').select('Banana').should('have.value', 'Apple, Banana')

Solution

  1. Step 1: Understand multi-select usage in cy.select()

    To select multiple options, pass an array of option texts or values to cy.select().
  2. Step 2: Check assertion for multiple values

    The assertion should check that the dropdown's value matches the array of selected options.
  3. Step 3: Eliminate incorrect chaining and string formats

    Chaining multiple select() calls does not accumulate selections. Passing a comma-separated string selects one option matching that exact string, which is invalid.
  4. Final Answer:

    cy.get('#fruits').select(['Apple', 'Banana']).should('have.value', ['Apple', 'Banana']) -> Option C
  5. Quick Check:

    Use array to select multiple options [OK]
Hint: Pass array of options to select multiple [OK]
Common Mistakes:
  • Passing comma-separated string instead of array
  • Chaining select() calls expecting multiple selections
  • Incorrect assertion for multiple values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard