--- title: click comments: true --- Click a DOM element. # Syntax ```javascript .click() .click(options) .click(position) .click(position, options) .click(x, y) .click(x, y, options) ``` ## Usage `.click()` requires being chained off another cy command that *yields* a DOM element. **{% fa fa-check-circle green %} Valid Usage** ```javascript cy.get('button').click() // Click on button cy.focused().click() // Click on el with focus cy.contains('Welcome').click() // Click on first el containing 'Welcome' ``` **{% fa fa-exclamation-triangle red %} Invalid Usage** ```javascript cy.click('button') // Errors, cannot be chained off 'cy' cy.window().click() // Errors, 'window' does not yield DOM element ``` ## Arguments **{% fa fa-angle-right %} position** ***(String)*** The position where the 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](https://cloud.githubusercontent.com/assets/1271364/25048528/fe0c6378-210a-11e7-96bc-3773f774085b.jpg) **{% fa fa-angle-right %} x** ***(Number)*** The distance in pixels from the element's left to issue the click. **{% fa fa-angle-right %} y** ***(Number)*** The distance in pixels from the element's top to issue the click. **{% fa fa-angle-right %} options** ***(Object)*** Pass in an options object to change the default behavior of `.click()`. Option | Default | Notes --- | --- | --- `force` | `false` | Force click, disables error checking prior to click `interval` | `16` | Interval which to retry a click `log` | `true` | Whether to display command in Command Log `multiple` | `false` | Enable serially clicking multiple elements `timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry the click ## Yields `.click()` yields the element that was clicked. ## Timeout `.click()` will wait until the element is in a 'clickable' state for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's options. # Examples ## Click **Click the button** ```javascript cy.get('button').click() ``` ## Position **Specify a corner of the element to click** Click the top right corner of the button. ```javascript cy.get('button').click('topRight') ``` ## Coordinates **Specify explicit coordinates relative to the top left corner** The click below will be issued inside of the element (15px from the left and 40px from the top). ```javascript cy.get('button').click(15, 40) ``` ## Options **Force a click regardless of visibility or other elements in front of the element** Forcing a click is useful when you want the click issued no matter what. Forcing a click disables checking that this element is visible and in a clickable state before clicking. ```javascript cy.get('button').click({ force: true }) ``` {% note warning %} Be careful with this option! It may allow the click to happen when it would be impossible for a real user to click. {% endnote %} **Force a click with position argument** ```javascript cy.get('button').click('bottomLeft', { force: true }) ``` **Force a click with relative coordinates** ```javascript cy.get('button').click(5, 60, { force: true }) ``` **Hover and clicking hidden elements** {% note info %} [Check out our example recipe on testing hover and working with hidden elements.](https://github.com/cypress-io/cypress-example-recipes/blob/master/cypress/integration/hover_hidden_elements_spec.js) {% endnote %} **Click all buttons found on the page** ```javascript cy.get('button').click({ multiple: true }) ``` # Notes **Events that are fired** ```javascript cy.get('button').click() // mousedown // focus // mouseup // click ``` The events are fired to spec, including the coordinates of where the event took place. At the moment, `mouseover` and `mouseout` events are *not* fired. [Open an issue](https://github.com/cypress-io/cypress/issues/new) if you need this to be fixed. Additionally if the `mousedown` event causes the element to be removed from the DOM, the remaining events should continue to be fired, but to the resulting element left below the removed element. This has also not been implemented. [Open an issue](https://github.com/cypress-io/cypress/issues/new) if you need this to be fixed. **Focus is given to the first focusable element** Clicking a ``, for example, inside of a `