0
0
Cypresstesting~20 mins

cy.type() for text input in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Typing Master
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 snippet that types text into an input field. What will be the value of the input after running this code?
Cypress
cy.get('#username').type('hello').type('{backspace}').type('p');
cy.get('#username').invoke('val').then(value => cy.wrap(value));
A"hellp"
B"hello"
C"help"
D"hell"
Attempts:
2 left
💡 Hint
Remember that {backspace} removes the last character typed before it.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the input value after typing?
You want to check that the input with id 'email' contains the text 'test@example.com' after typing. Which assertion is correct?
Cypress
cy.get('#email').type('test@example.com');
Acy.get('#email').should('contain.text', 'test@example.com');
Bcy.get('#email').should('include.value', 'test@example.com');
Ccy.get('#email').should('have.text', 'test@example.com');
Dcy.get('#email').should('have.value', 'test@example.com');
Attempts:
2 left
💡 Hint
Input fields store typed text in the 'value' attribute, not as inner text.
locator
advanced
2:30remaining
Which locator is best for typing into a password field with accessibility in mind?
You want to type into a password input field that has a label 'Password'. Which locator is the best practice for accessibility and reliability?
Acy.get('input[type="password"]')
Bcy.get('#password')
Ccy.contains('label', 'Password').invoke('attr', 'for').then(id => cy.get(`#${id}`))
Dcy.get('input').eq(1)
Attempts:
2 left
💡 Hint
Using the label's 'for' attribute links the label to the input, improving accessibility.
🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail to type text into the input?
Look at this code snippet: cy.get('#search').type('query'); But the test fails with error: "cy.type() failed because this element is disabled". What is the most likely cause?
AThe input element has the 'disabled' attribute set, preventing typing.
BThe selector '#search' is incorrect and selects no element.
CThe input is hidden with CSS 'display:none', so typing is blocked.
DThe test is missing a .click() before .type(), so the input is not focused.
Attempts:
2 left
💡 Hint
Cypress cannot type into inputs that are disabled by HTML attributes.
framework
expert
2:30remaining
How to simulate typing with delay between keystrokes in Cypress?
You want to simulate a user typing slowly into an input with id 'comment'. Which code snippet correctly types 'hello' with a 100ms delay between each character?
Acy.get('#comment').type('hello').wait(100);
Bcy.get('#comment').type('hello', { delay: 100 });
Ccy.get('#comment').type('hello', { delayBetween: 100 });
Dcy.get('#comment').type('h').wait(100).type('e').wait(100).type('l').wait(100).type('l').wait(100).type('o');
Attempts:
2 left
💡 Hint
Check the official Cypress docs for the correct option name for delay.