Cypress Click with Key Combinations

Profile picture for user arilio666

Cypress click() command can be used with key modifiers for real-time combination clicks suck as ALT+Click.

The following Keys can be combined with the click command through the options.

  1. altKey
  2. ctrlKey
  3. shiftKey
  4. metaKey(Windows Key/Command Key)
cy.get('locator').click({
 ctrlKey: true,
})

Example:

Let us use the control key and check whether a new tab opens.

     cy.visit('https://www.programsbuzz.com/').as('site')
      cy.get('.fas.fa-search').click()
      cy.get('#edit-keys').type('Cypress')
      cy.get('#edit-submit').click({
       ctrlKey: true,
     })
  
Cypress Click with Key Combinations