How to Press Enter and Other Special Keys in Cypress

How to Press Enter and Other Special Keys in Cypress

Ferenc Almasi β€’ 2022 August 24 β€’ Read time 1 min read
  • twitter
  • facebook

To press the enter key in your Cypress tests, you can use the type command with the following special characters:

Copied to clipboard!
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:

Copied to clipboard! Playground
// 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:

Learn Cypress with Educative
How to Press Enter and Other Special Keys in Cypress
If you would like to see more webtips, follow @flowforfrank

Resources:

  • twitter
  • facebook
Did you find this page helpful?
πŸ“š More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.