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.
- altKey
- ctrlKey
- shiftKey
- 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,
})
- Log in to post comments