0
0
Cypresstesting~20 mins

cy.clear() for input fields in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Clear Mastery Badge
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 snippet?
Consider the following Cypress test code that clears an input field and then types a new value. What will be the value of the input field after the test runs?
Cypress
cy.get('#username').type('oldValue').clear().type('newValue').invoke('val').then(value => {
  cy.wrap(value).as('finalValue')
})
A'oldValue'
B'' (empty string)
C'newValue'
Dundefined
Attempts:
2 left
💡 Hint
Remember that cy.clear() removes existing text before typing new text.
assertion
intermediate
1:30remaining
Which assertion correctly verifies an input field is empty after clearing?
You want to check that an input field with id 'email' is empty after using cy.clear(). Which assertion is correct?
Cypress
cy.get('#email').clear()
Acy.get('#email').should('contain.text', '')
Bcy.get('#email').should('have.value', '')
Ccy.get('#email').should('be.empty')
Dcy.get('#email').should('not.exist')
Attempts:
2 left
💡 Hint
Input fields have a 'value' attribute for their content.
locator
advanced
2:00remaining
Which locator is best for clearing a specific input field with Cypress?
You want to clear the password input field inside a form with id 'loginForm'. Which locator is the best practice to select this input for clearing?
Acy.get('input[type="password"]')
Bcy.get('.password-input')
Ccy.get('form input')
Dcy.get('#loginForm input[name="password"]')
Attempts:
2 left
💡 Hint
Use specific and stable selectors to avoid selecting wrong elements.
🔧 Debug
advanced
2:00remaining
Why does cy.clear() fail on this input field?
Given this HTML: and this Cypress code: cy.get('#search').clear(), why does the clear command fail?
AThe input is disabled, so cy.clear() cannot modify it.
BThe input has a value attribute, so clear is ignored.
Ccy.clear() requires the input to be visible, but it is hidden.
Dcy.clear() only works on textarea elements, not input.
Attempts:
2 left
💡 Hint
Disabled inputs cannot be changed by user actions.
framework
expert
2:30remaining
How to ensure cy.clear() waits for input readiness before clearing?
In a flaky test, cy.clear() sometimes fails because the input is not ready. Which Cypress command sequence best ensures the input is visible and enabled before clearing?
Acy.get('#input').should('be.visible').should('not.be.disabled').clear()
Bcy.get('#input').clear().should('be.visible').should('not.be.disabled')
Ccy.get('#input').clear({force: true})
Dcy.get('#input').wait(1000).clear()
Attempts:
2 left
💡 Hint
Use assertions to wait for conditions before actions.