{
  "doc": {
    "id": "api/commands/trigger",
    "title": "trigger | Cypress Documentation",
    "description": "Trigger an event on a DOM element in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/trigger.md",
    "version": "ce02913654e2655ee63448bdc92bb92c7b46a619",
    "updated_at": "2026-04-22T19:37:51.587Z",
    "headings": [
      {
        "id": "api/commands/trigger#trigger",
        "text": "trigger",
        "level": 1
      },
      {
        "id": "api/commands/trigger#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/trigger#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/trigger#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/trigger#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/trigger#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/trigger#mouse-events",
        "text": "Mouse Events",
        "level": 3
      },
      {
        "id": "api/commands/trigger#trigger-a-mouseover-on-the-button",
        "text": "Trigger a mouseover on the button",
        "level": 4
      },
      {
        "id": "api/commands/trigger#simulate-a-long-press-event",
        "text": "Simulate a \"long press\" event",
        "level": 4
      },
      {
        "id": "api/commands/trigger#trigger-a-mousedown-from-a-specific-mouse-button",
        "text": "Trigger a mousedown from a specific mouse button",
        "level": 4
      },
      {
        "id": "api/commands/trigger#jquery-ui-sortable",
        "text": "jQuery UI Sortable",
        "level": 4
      },
      {
        "id": "api/commands/trigger#drag-and-drop",
        "text": "Drag and Drop",
        "level": 4
      },
      {
        "id": "api/commands/trigger#change-event",
        "text": "Change Event",
        "level": 3
      },
      {
        "id": "api/commands/trigger#interact-with-a-range-input-slider",
        "text": "Interact with a range input (slider)",
        "level": 4
      },
      {
        "id": "api/commands/trigger#position",
        "text": "Position",
        "level": 3
      },
      {
        "id": "api/commands/trigger#trigger-a-mousedown-on-the-top-right-of-a-button",
        "text": "Trigger a mousedown on the top right of a button",
        "level": 4
      },
      {
        "id": "api/commands/trigger#coordinates",
        "text": "Coordinates",
        "level": 3
      },
      {
        "id": "api/commands/trigger#specify-explicit-coordinates-relative-to-the-top-left-corner",
        "text": "Specify explicit coordinates relative to the top left corner",
        "level": 4
      },
      {
        "id": "api/commands/trigger#options",
        "text": "Options",
        "level": 3
      },
      {
        "id": "api/commands/trigger#specify-that-the-event-should-not-bubble",
        "text": "Specify that the event should not bubble",
        "level": 4
      },
      {
        "id": "api/commands/trigger#specify-the-exact-clientx-and-clienty-the-event-should-have",
        "text": "Specify the exact clientX and clientY the event should have",
        "level": 4
      },
      {
        "id": "api/commands/trigger#fire-other-event-types",
        "text": "Fire other Event types.",
        "level": 3
      },
      {
        "id": "api/commands/trigger#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/trigger#actionability",
        "text": "Actionability",
        "level": 3
      },
      {
        "id": "api/commands/trigger#the-element-must-first-reach-actionability",
        "text": "The element must first reach actionability",
        "level": 4
      },
      {
        "id": "api/commands/trigger#events",
        "text": "Events",
        "level": 3
      },
      {
        "id": "api/commands/trigger#what-event-should-i-fire",
        "text": "What event should I fire?",
        "level": 4
      },
      {
        "id": "api/commands/trigger#why-should-i-manually-set-the-event-type",
        "text": "Why should I manually set the event type?",
        "level": 4
      },
      {
        "id": "api/commands/trigger#differences",
        "text": "Differences",
        "level": 3
      },
      {
        "id": "api/commands/trigger#whats-the-difference-between-triggering-and-event-and-calling-the-corresponding-cypress-command",
        "text": "What's the difference between triggering and event and calling the corresponding cypress command?",
        "level": 4
      },
      {
        "id": "api/commands/trigger#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/trigger#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/trigger#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/trigger#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/trigger#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/trigger#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/trigger#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "trigger"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Trigger an event on a DOM element."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "It is "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried",
            "children": [
              {
                "type": "text",
                "value": "unsafe"
              }
            ]
          },
          {
            "type": "text",
            "value": " to\nchain further commands that rely on the subject after `.trigger()`."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": ".trigger(eventName)\n.trigger(eventName, position)\n.trigger(eventName, options)\n.trigger(eventName, x, y)\n.trigger(eventName, position, options)\n.trigger(eventName, x, y, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('a').trigger('mousedown') // Trigger mousedown event on link"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.trigger('touchstart') // Errors, cannot be chained off 'cy'\ncy.clock().trigger('mouseleave') // Errors, 'clock' does not yield DOM elements"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "eventName (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The name of the `event` to be triggered on the DOM element."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "position (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The position where the event should be triggered. The `center` position is the\ndefault position. Valid positions are `topLeft`, `top`, `topRight`, `left`,\n`center`, `right`, `bottomLeft`, `bottom`, and `bottomRight`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "x (Number)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The distance in pixels from element's left to trigger the event."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "y (Number)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The distance in pixels from element's top to trigger the event."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `.trigger()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`animationDistanceThreshold`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Actionability",
                    "children": [
                      {
                        "type": "text",
                        "value": "`animationDistanceThreshold`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The distance in pixels an element must exceed over time to be "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations",
                    "children": [
                      {
                        "type": "text",
                        "value": "considered animating"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`bubbles`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Whether the event bubbles"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`cancelable`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Whether the event is cancelable"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`eventConstructor`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`Event`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The constructor for creating the event object (e.g. `MouseEvent`, `KeyboardEvent`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`force`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`false`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Forces the action, disables "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "waiting for actionability"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`scrollBehavior`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Actionability",
                    "children": [
                      {
                        "type": "text",
                        "value": "`scrollBehavior`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Viewport position to where an element "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md#Scrolling",
                    "children": [
                      {
                        "type": "text",
                        "value": "should be scrolled"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " before executing the command"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `.trigger()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`waitForAnimations`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Actionability",
                    "children": [
                      {
                        "type": "text",
                        "value": "`waitForAnimations`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Whether to wait for elements to "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations",
                    "children": [
                      {
                        "type": "text",
                        "value": "finish animating"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " before executing the command."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can also include arbitrary event properties (e.g. `clientX`, `shiftKey`) and\nthey will be attached to the event. Passing in coordinate arguments (`clientX`,\n`pageX`, etc) will override the position coordinates."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management",
            "children": [
              {
                "type": "text",
                "value": "Learn about subject management"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` yields the same subject it was given."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "It is "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried",
                    "children": [
                      {
                        "type": "text",
                        "value": "unsafe"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "\nto chain further commands that rely on the subject after `.trigger()`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Mouse Events"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Trigger a mouseover on the button"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The DOM element must be in an \"interactable\" state prior to the triggered event\nhappening (it must be visible and not disabled)."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('mouseover') // yields 'button'"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Simulate a \"long press\" event"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('.target').trigger('mousedown')\ncy.wait(1000)\ncy.get('.target').trigger('mouseup')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Trigger a mousedown from a specific mouse button"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// Main button pressed (usually the left button)\ncy.get('.target').trigger('mousedown', { button: 0 })\n// Auxiliary button pressed (usually the middle button)\ncy.get('.target').trigger('mousedown', { button: 1 })\n//Secondary button pressed (usually the right button)\ncy.get('.target').trigger('mousedown', { button: 2 })"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "jQuery UI Sortable"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To simulate drag and drop using jQuery UI sortable requires `pageX` and `pageY`\nproperties along with `which:1`."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('[data-cy=draggable]').trigger('mousedown', {\n  which: 1,\n  pageX: 600,\n  pageY: 100,\n})\ncy.get('[data-cy=draggable]').trigger('mousemove', {\n  which: 1,\n  pageX: 600,\n  pageY: 600,\n})\ncy.get('[data-cy=draggable]').trigger('mouseup')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Drag and Drop"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/recipes.md#Testing-the-DOM",
            "children": [
              {
                "type": "text",
                "value": "Check out our example recipe triggering mouse and drag events to test drag and drop"
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Change Event"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Interact with a range input (slider)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To interact with a range input (slider), we need to set its value and then\ntrigger the appropriate event to signal it has changed."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Below we invoke jQuery's `val()` method to set the value, then trigger the\n`change` event."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note that some implementations may rely on the `input` event instead, which is\nfired as a user moves the slider, but is not supported by some browsers."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('input[type=range]').as('range').invoke('val', 25).trigger('change')\n\ncy.get('@range').siblings('p').should('have.text', '25')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Position"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Trigger a mousedown on the top right of a button"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('mousedown', 'topRight')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Coordinates"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Specify explicit coordinates relative to the top left corner"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('mouseup', 15, 40)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Options"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Specify that the event should not bubble"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, the event will bubble up the DOM tree. This will prevent the event\nfrom bubbling."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('mouseover', { bubbles: false })"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Specify the exact clientX and clientY the event should have"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "This overrides the default auto-positioning based on the element itself. Useful\nfor events like `mousemove` where you need the position to be outside the\nelement itself."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('mousemove', { clientX: 200, clientY: 300 })"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Fire other Event types."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, `cy.trigger()` fires\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "https://developer.mozilla.org/en-US/docs/Web/API/Event",
            "children": [
              {
                "type": "text",
                "value": "`Event`"
              }
            ]
          },
          {
            "type": "text",
            "value": ". But you may\nwant to trigger other events like `MouseEvent` or `KeyboardEvent`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In that case, use the `eventConstructor` option."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.get('button').trigger('mouseover', { eventConstructor: 'MouseEvent' })"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Actionability"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "The element must first reach actionability"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.trigger()` is an \"action command\" that follows all the rules of\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
            "children": [
              {
                "type": "text",
                "value": "Actionability"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Events"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "What event should I fire?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.trigger()` is meant to be a low-level utility that makes triggering events\neasier than manually constructing and dispatching them. Since any arbitrary\nevent can be triggered, Cypress tries not to make any assumptions about how it\nshould be triggered. This means you'll need to know the implementation details\n(which may be in a 3rd party library) of the event handler(s) receiving the\nevent and provide the necessary properties."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Why should I manually set the event type?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "As you can see the documentation of\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent",
            "children": [
              {
                "type": "text",
                "value": "`MouseEvent`"
              }
            ]
          },
          {
            "type": "text",
            "value": ",\nmost properties of event class instances are read-only. Because of that, it's\nsometimes impossible to set the value of some properties like `pageX`, `pageY`.\nThis can be problematic in when testing some situations."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Differences"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "What's the difference between triggering and event and calling the corresponding cypress command?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In other words, what's the difference between:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('button').trigger('focus')\ncy.get('button').focus()\n\n// ... or ...\n\ncy.get('button').trigger('click')\ncy.get('button').click()"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Both types commands will first verify element actionability, but only the \"true\"\naction commands will implement all of the default actions of the browser, and\nadditionally perform low level actions to fulfill what's defined in the spec."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.trigger()` will only fire the corresponding event and do nothing else."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "That means that your event listener callbacks will be invoked, but don't expect\nthe browser to actually \"do\" anything for these events. For the most part, it\nshouldn't matter, which is why `.trigger()` is an excellent stop-gap if the\ncommand / event you're looking for hasn't been implemented yet."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands",
            "children": [
              {
                "type": "text",
                "value": "Learn about chaining commands"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` requires being chained off a command that yields DOM element(s)."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions",
            "children": [
              {
                "type": "text",
                "value": "Learn about assertions"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` will automatically wait for the element to reach an\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "actionable state"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "\nuntil all chained assertions have passed."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts",
            "children": [
              {
                "type": "text",
                "value": "Learn about timeouts"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` can time out waiting for the element to reach an\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "actionable state"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` can time out waiting for assertions you've added to pass."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Trigger a `change` event on input type='range'"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.get('.trigger-input-range').invoke('val', 25).trigger('change')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above will display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When clicking on `trigger` within the command log, the console outputs the\nfollowing:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#6-1-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "6.1.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added option `scrollBehavior`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#3-5-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "3.5.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `screenX` and `screenY` properties to events"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#0-20-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "0.20.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`.trigger()` command added"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/blur.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.blur()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/check.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.check()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/click.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.click()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/focus.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.focus()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/rightclick.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.rightclick()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/select.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.select()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/submit.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.submit()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/type.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.type()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/uncheck.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.uncheck()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1625
}