rightclick
Right click a DOM element.
It is unsafe to
chain further commands that rely on the subject after .rightclick()
.
.rightclick()
will not open context menus native to the browser.
.rightclick()
should be used to test your app's handling of right click
related events such as contextmenu
.
Syntax​
.rightclick()
.rightclick(options)
.rightclick(position)
.rightclick(position, options)
.rightclick(x, y)
.rightclick(x, y, options)
Usage​
Correct Usage
cy.get('.menu').rightclick() // Right click on .menu
cy.focused().rightclick() // Right click on el with focus
cy.contains('Today').rightclick() // Right click on first el containing 'Today'
Incorrect Usage
cy.rightclick('button') // Errors, cannot be chained off 'cy'
cy.window().rightclick() // Errors, 'window' does not yield DOM element
Arguments​
position (String)
The position where the right click should be issued. The center
position is
the default position. Valid positions are topLeft
, top
, topRight
, left
,
center
, right
, bottomLeft
, bottom
, and bottomRight
.
x (Number)
The distance in pixels from the element's left to issue the right click.
y (Number)
The distance in pixels from the element's top to issue the right click.
options (Object)
Pass in an options object to change the default behavior of .rightclick()
.
Option | Default | Description |
---|---|---|
altKey | false | Activates the alt key (option key for Mac). Aliases: optionKey . |
animationDistanceThreshold | animationDistanceThreshold | The distance in pixels an element must exceed over time to be considered animating. |
ctrlKey | false | Activates the control key. Aliases: controlKey . |
force | false | Forces the action, disables waiting for actionability |
log | true | Displays the command in the Command log |
metaKey | false | Activates the meta key (Windows key or command key for Mac). Aliases: commandKey , cmdKey . |
multiple | false | Serially click multiple elements |
scrollBehavior | scrollBehavior | Viewport position to where an element should be scrolled before executing the command |
shiftKey | false | Activates the shift key. |
timeout | defaultCommandTimeout | Time to wait for .rightclick() to resolve before timing out |
waitForAnimations | waitForAnimations | Whether to wait for elements to finish animating before executing the command. |
Yields ​
.rightclick()
yields the same subject it was given.- It is unsafe
to chain further commands that rely on the subject after
.rightclick()
.
Examples​
No Args​
Right click the menu​
cy.get('#open-menu').rightclick()
Position​
Specify a corner of the element to right click​
Right click the top right corner of the DOM element.
cy.get('#open-menu').rightclick('topRight')
Coordinates​
Specify explicit coordinates relative to the top left corner​
The right click below will be issued inside of the element (15px from the left and 40px from the top).
cy.get('#open-menu').rightclick(15, 40)
Options​
Force a right click regardless of its actionable state​
Forcing a right click overrides the actionable checks Cypress applies and will automatically fire the events.
cy.get('#open-menu').rightclick({ force: true })