How to Press Enter and Other Special Keys in Cypress
To press the enter key in your Cypress tests, you can use the type
command with the following special characters:
cy.get('input').type('{enter}')
This will tell Cypress to simulate a click on the enter key. There are other supported special character sequences in Cypress that can simulate key presses. These can be categorized into the following three different groups:
// Special characters:
cy.get('input').type('{enter}')
cy.get('input').type('{backspace}')
cy.get('input').type('{del}')
cy.get('input').type('{esc}')
cy.get('input').type('{end}')
cy.get('input').type('{home}')
cy.get('input').type('{insert}')
cy.get('input').type('{moveToEnd}') // Move cursor to the end of typeable element
cy.get('input').type('{moveToStart}') // Move cursor to the start of typeable element
cy.get('input').type('{pageDown}') // Scroll down
cy.get('input').type('{pageUp}') // Scroll up
cy.get('input').type('{selectAll}') // Select the entire input value
// Arrows:
cy.get('input').type('{upArrow}')
cy.get('input').type('{downArrow}')
cy.get('input').type('{leftArrow}')
cy.get('input').type('{rightArrow}')
// Modifier keys:
cy.get('input').type('{shift}')
cy.get('input').type('{ctrl}')
cy.get('input').type('{alt}')
Want to learn Cypress from end to end? Check out my Cypress course on Educative where I cover everything:
Resources:
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: