Join us December 11th at 2PM EST/11AM PST to learn how the Siemens SW Hub Cloud Team increased their productivity by 38% with Cypress

Register

dblclick

Improve this doc

Double-click a DOM element.

Syntax

.dblclick()
.dblclick(options)
.dblclick(position)
.dblclick(position, options)
.dblclick(x, y)
.dblclick(x, y, options)

Usage

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'

Incorrect Usage

cy.dblclick('button')          // Errors, cannot be chained off 'cy'
cy.window().dblclick()         // Errors, 'window' does not yield DOM element

Arguments

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.

cypress-command-positions-diagram

x (Number)

The distance in pixels from the element’s left to issue the double click.

y (Number)

The distance in pixels from the element’s top to issue the double click.

options (Object)

Pass in an options object to change the default behavior of .dblclick().

Option Default Description
log true Displays the command in the Command log
force false Forces the action, disables waiting for actionability
multiple true Serially click multiple elements
timeout defaultCommandTimeout Time to wait for .dblclick() to resolve before timing out

Yields

  • .dblclick() yields the same subject it was given from the previous command.

Examples

No Args

Double click an anchor link

cy.get('a#nav1').dblclick() // yields the <a>

Position

Specify a position of the element to double click

Click the bottom center of the button.

cy.get('button').dblclick('bottom')

Coordinates

Specify coordinates relative to the top left corner

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)

Options

Force a double click regardless of its actionable state

Forcing a double click overrides the actionable checks Cypress applies and will automatically fire the events.

cy.get('button').dblclick({ force: true })

Force a double click with position argument

cy.get('button').dblclick('topRight', { force: true })

Force a double click with relative coordinates

cy.get('button').dblclick(60, 60, { force: true })

Double click all buttons found on the page

By default, Cypress will iteratively apply the double click to each element and will also log to the Command Log multiple times.

You can turn this off by passing multiple: false to .dblclick().

cy.get('button').dblclick({ multiple: false })

Double click with key combinations

The .dblclick() command may also be fired with key modifiers in combination with the .type() command in order to simulate character sequences while double clicking, such as SHIFT + double click. In order to keep the modifier key active, {release: false} should be passed to the options of the .type() command.

The following modifiers can be combined with .dblclick().

Sequence Notes
{alt} Activates the altKey modifier. Aliases: {option}
{ctrl} Activates the ctrlKey modifier. Aliases: {control}
{meta} Activates the metaKey modifier. Aliases: {command}, {cmd}
{shift} Activates the shiftKey modifier.

Alt click

// execute a ALT + dblclick on the first <li>
// { release: false } is necessary so that
// ALT will not be released after the type command
cy.get('body').type('{alt}', { release: false })
cy.get('li:first').dblclick()

Notes

Actionability

The element must first reach actionability

.dblclick() is an “action command” that follows all the rules defined here.

Rules

Requirements

  • .dblclick() requires being chained off a command that yields DOM element(s).

Assertions

  • .dblclick() will automatically wait for the element to reach an actionable state.

  • .dblclick() will automatically wait for assertions you've chained to pass.

Timeouts

  • .dblclick() can time out waiting for the element to reach an actionable state.

  • .dblclick() can time out waiting for assertions you've added to pass.

Command Log

Double click on a div

cy.get('.action-div').dblclick()

The commands above will display in the Command Log as:

Command Log dblclick

When clicking on dblclick within the command log, the console outputs the following:

console.log dblclick

History

Version Changes
3.5.0 Added support for options force and multiple.
3.5.0 Added support for position, x, and y arguments.
3.5.0 Added sending mouseover, mousemove, mouseout, pointerdown, pointerup, and pointermove during .dblclick().

See also