| title | dblclick |
|---|
Double-click a DOM element.
.dblclick()
.dblclick(options)
.dblclick(position)
.dblclick(position, options)
.dblclick(x, y)
.dblclick(x, y, options){% fa fa-check-circle green %} Correct Usage
cy.get('button').dblclick() // Double click on button
cy.focused().dblclick() // Double click on el with focus
cy.contains('Welcome').dblclick() // Double click on first el containing 'Welcome'{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.dblclick('button') // Errors, cannot be chained off 'cy'
cy.window().dblclick() // Errors, 'window' does not yield DOM element{% fa fa-angle-right %} position (String)
The position where the double click should be issued. The center position is the default position. Valid positions are topLeft, top, topRight, left, center, right, bottomLeft, bottom, and bottomRight.
{% imgTag "/img/api/coordinates-diagram.jpg" "cypress-command-positions-diagram" %}
{% fa fa-angle-right %} x (Number)
The distance in pixels from the element's left to issue the double click.
{% fa fa-angle-right %} y (Number)
The distance in pixels from the element's top to issue the double click.
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .dblclick().
| Option | Default | Description |
|---|---|---|
altKey |
false |
{% usage_options altKey %} |
ctrlKey |
false |
{% usage_options ctrlKey %} |
log |
true |
{% usage_options log %} |
force |
false |
{% usage_options force dblclick %} |
metaKey |
false |
{% usage_options metaKey %} |
multiple |
true |
{% usage_options multiple dblclick %} |
shiftKey |
false |
{% usage_options shiftKey %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .dblclick %} |
{% yields same_subject .dblclick %}
cy.get('a#nav1').dblclick() // yields the <a>Click the bottom center of the button.
cy.get('button').dblclick('bottom')The double click below will be issued inside of the element (30px from the left and 10px from the top).
cy.get('button').dblclick(30, 10)Forcing a double click overrides the {% url 'actionable checks' interacting-with-elements#Forcing %} Cypress applies and will automatically fire the events.
cy.get('button').dblclick({ force: true })cy.get('button').dblclick('topRight', { force: true })cy.get('button').dblclick(60, 60, { force: true })By default, Cypress will iteratively apply the double click to each element and will also log to the {% url 'Command Log' test-runner#Command-Log %} multiple times.
You can turn this off by passing multiple: false to .dblclick().
cy.get('button').dblclick({ multiple: false })The .dblclick() command may also be fired with key modifiers in order to simulate holding key combinations while double clicking, such as SHIFT + double click.
{% note info %}
You can also use key combinations during {% url ".type()" type %}. This offers options to hold down keys across multiple commands. See {% url "Key Combinations" type#Key-Combinations %} for more information.
{% endnote %}
The following modifiers can be combined with .dblclick().
| Option | Notes |
|---|---|
altKey |
{% usage_options altKey %} |
ctrlKey |
{% usage_options ctrlKey %} |
metaKey |
{% usage_options metaKey %} |
shiftKey |
{% usage_options shiftKey %} |
// execute ALT + dblclick on the first <li>
cy.get('li:first').dblclick({
altKey: true
}).dblclick() is an "action command" that follows all the rules {% url 'defined here' interacting-with-elements %}.
{% requirements dom .dblclick %}
{% assertions actions .dblclick %}
{% timeouts actions .dblclick %}
Double click on a div
cy.get('.action-div').dblclick()The commands above will display in the Command Log as:
{% imgTag /img/api/dblclick/double-click-in-testing.png "Command Log dblclick" %}
When clicking on dblclick within the command log, the console outputs the following:
{% imgTag /img/api/dblclick/element-double-clicked-on.png "console.log dblclick" %}
{% history %}
{% url "3.5.0" changelog#3-5-0 %} | Added support for options force and multiple.
{% url "3.5.0" changelog#3-5-0 %} | Added support for position, x, and y arguments.
{% url "3.5.0" changelog#3-5-0 %} | Added sending mouseover, mousemove, mouseout, pointerdown, pointerup, and pointermove during .dblclick().
{% endhistory %}
- {% url
.click()click %} - {% url
.rightclick()rightclick %}