Handling Touch and Mouse events using Cypress
On This Page What are Touch and Mouse Events in Cypress?February 27, 2026 · 11 min read · Tool Comparison
While testing web-based covering, the mouse and touch events are the most normally performed events. In layman ’ s price, mouse events can be defined as any activity do using the shiner. What are Mouse Events? Mouse events refer to events triggered by mouse activity such as clicking, hovering, or haul with a shiner or trackpad. What are Touch Events? Touch events are triggered by touch-based activity like swiping, tapping, etc., on touch interface devices. Commands to Handle Mouse Events in Cypress Touch Events in Cypress Read this guide further to learn in particular about how to handle touch and mouse case in. Touch and Mouse Events in Cypress simulate how users behave with web apps, either through a mouse or touchscreen. These case can be feign in Cypress via commands like .click (), .dblclick (), or .trigger () etc., to prove and verify the related UI behaviors across respective gimmick types. Read More: Here are the various ways in which you can do the shiner events on Cypress The clickcommand in Cypress do the click action on the specified DOM element Syntax: Example: Click the Product menu Variations of the click command in Cypress Example: The dblclick ()command performs the double click action in Cypress Automation. The ordinarily used dblclick () command is Example: The double click comes with multiple variants in Cypress The duple click get with multiple variants in Cypress Example: Example: Example: Example: Example: If your apps are project to handleright-clickevent then you can use the rightclick () command in Cypress to simulate the right-click actions. Note: 1. The Cypress .rightclick () will not open circumstance menu aboriginal to the browser. Typically correct click can be used with the below syntax Example: Variants of right-click dictation in Cypress Example: SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. The Cypresscheck and uncheck command helps perform a check and uncheck actions on the radio button or checkbox. The Cypress assay command Syntax The .check()option is most commonly used, the.check() bidding needs to be chained with locator. Example: The .check () command too accept the value, the value is the value attribute in HTML Considering the above HTML if you take to click on the Apple radio button, you can write the bidding below Note: The check command also have multiple values. The uncheck command make the paired action of the check command. The uncheck command can be expend to uncheck a single checkbox or multiple checkboxes at once. Cypress Uncheck Command Syntax Example: The Cypress trigger command is almost useful while writing functional trial lawsuit. Using the Cypress trigger dictation, you can actuate any DOM case. Example: You can do a click action expend the trigger dictation Similarly, you can pass any event from the list of uncommittedeventsthat Cypress support. The cypress mouseover is supported viatrigger bid; there is no native support in Cypress. However, the mouseover can be achieved easily using the trigger bid. Example: You might have a scenario where you need to long pressure the shiner for 5 seconds you can achieve that functionality through the mouseup and mousedown event. Read More: The mousemove case hap when the arrow is displace while it is over an constituent. The Mouse leave event occurs when the mouse pointer is moved out of an component. Example: The Cypress scroll into view command scroll the specified element into panorama. The scrollIntoView bidding accepts choice.scrollIntoView (options), such as easing aliveness, offset, duration etc. The Cypress select command help to select the alternative within the quality tag. For example, if you have a select fruit choice and from the drop-down, you can select any one of apple, orangeness, kiwi, etc. Syntax: Note: 1. The select bidding accepts text, value, or indicant. For example, the above bid can also be utilise ascy.get (& # 8216; # fruit & # 8217;) .select (0); Touch event are similar to creep events. Touch case supports simultaneous ghost at different fix on touch-based surfaces. To perform a touch event, you must have a touch interface device. Smartphones are an excellent exemplar of touch-based devices. Here are the usually habituate Touch Events: The touch start event is triggered when the user places the touch point on the touch interface. Command Syntax The touch end case is triggered when the exploiter removes a touch point from the touch interface; that is, when they elevate a finger or stylus from the touch interface. Command Syntax The touch move case pass when the exploiter moves a touch point along the touch surface. Command Syntax Touch cancel event induction when the trace point has been disrupted for some reason. A typical example is if the device supports single touch and the exploiter tries to use multiple fingers, it will be like multi-touch, so this case may pass. Command Syntax Read More: Cypress touch event example The cy.trigger ()bidding can trigger the touch case in Cypress. Note: Your application and twist should support the touch event before get any touch action. Mobile gimmick quiz can be done in Cypress habituate thecy.viewport ()bidding is supported using the device emulation technique. Let & # 8217; s take a use lawsuit of do a touch case on iPhone-XR that can be achieved in cypress employ the below code Output: Similar way you can trigger any touch events in Cypress. Here are some best practices and tips you can follow for Cypress shiner and touch events: 1. Cypress supports click, double click right click and many more events out of the box use .click (), .dblclick () etc. The same operations can be performed using cy.trigger () command as well.Example: 2. The .focus () command can be used to focus on any input element Example: 3. The Cypress & # 8217; s .submit () can be employ for form submission 4. Cypress provides .clear () command, which helps to clear the text content input field (Works only on input or text area) Example: 5. The selectFile command in Cypress helps to drag and drop file in an HTML 5 input element. Generally used for dragging the file to the browser Example: You can choose multiple file as well. Read More: BrowserStack Automate ’ s cloud-based testing platform lets you run Cypress tests effectively across multiple device-OS-browser combinations. Here ’ s why choosing BrowserStack could enhance your Cypress testing efforts up a notch: In the mod existence with advanced technology, you can not trammel the exploiter to a specific browser or platform. When the application is back for multiple browsers and platforms, you must ensure it is working as expected. As Cypress support multiple browsers and function system, you can quickly test your application across the program and browser. The major problem with cross-platform testing is infrastructure apparatus and maintenance. Many organizations are moving towards to address this complicated problem. Browserstack provides thousands of real devices, include various wandering platform and adaptation which helps to test the production and confidently ship the product to market. Understanding Cypress Use Cases Tool Comparisons On This Page # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Handling Touch and Mouse events using Cypress
Overview
What are Touch and Mouse Events in Cypress?
Handling Mouse Events in Cypress Test Automation
1. Cypress Mouse Click Event
.click()
cy.get (' # productmenu ') .click ();
Example: cy.get (' # productmenu ') .click ({force: true})cy.get (' # tiger_image ') .click ('topRight ')cy.get (' # tiger_image ') .click ('topRight ', {force: true})cy.get (' # event-banner ') .click (15, 40)cy.get (' # event-banner ') .click (15, 40, {forcefulness: true})2. Cypress Double Click case
.dblclick ()
cy.get (' # some_id ') .dblclick ();cy.get (' # some_id ') .dblclick ({force: true});cy.get (' # some_id ') .dblclick ({force: true});cy.get (' # tiger_image '). dblclick ('topRight ')cy.get (' # tiger_image '). dblclick ('topRight ', {force: true})cy.get (' # event-banner '). dblclick (15, 40)cy.get (' # event-banner '). dblclick (15, 40, {force: true})3. Cypress Right Click Event
2. The Cypress .rightclick () should be used to test your app & # 8217; s handling of right-click-related event such as context menu.rightclick ()
cy.get (' # carte ') .rightclick ()cy.get (' # menu '). rightclick ({multiple: true})cy.get (' # menu '). rightclick ('bottomLeft ')cy.get (' # menu '). rightclick ('bottomLeft ', {strength: true})cy.get (' # right-menu ') .rightclick (15, 40)cy.get (' # right-menu ') .rightclick (5, 60, {forcefulness: true})4. Cypress Check and Uncheck commands
.check () .check (value) .check (value) .check (options) .check (value, options) .check (values, options)
cy.get (' [type= '' checkbox ''] ') .check ()& lt; form & gt; & lt; input type= '' radio '' value= '' APL '' / & gt; & lt; label for= '' importedfruit `` & gt; Apple & lt; /label & gt; & lt; input type= '' radio '' value= '' ORN '' / & gt; & lt; label for= '' countryfruit `` & gt; Orange & lt; /label & gt; & lt; /form & gt;
cy.get (' [type= '' radio ''] ') .check ('APL ').uncheck () .uncheck (value) .uncheck (value) .uncheck (options) .uncheck (value, options) .uncheck (value, options)
cy.get (' [type= '' checkbox ''] ') .uncheck () // Unchecks checkbox element cy.get ('input [type= '' checkbox ''] ') .uncheck (['car ']) // Uncheck the checkbox with the value of 'car' cy.get (' [type= '' checkbox ''] ') .uncheck (['car ', 'bus ']) // Uncheck the checkbox with the value 'car ' and 'bus '5. Cypress Trigger dictation
The Cypress trigger command syntax .trigger (eventName) .trigger (eventName, perspective) .trigger (eventName, options) .trigger (eventName, x, y) .trigger (eventName, position, option) .trigger (eventName, x, y, selection)
cy.get ('input [name= '' btnK ''] ') .first () .trigger ('click ');6. Cypress Mouseover event
cy.get (' # changecolor ') .trigger ('mouseover ')7. Mouse up and Mouse Down Event
Example: cy.get ('.target ') .trigger ('mousedown ') cy.wait (5000) cy.get ('.target ') .trigger ('mouseup ')8. Mouse Move Event
Example: cy.get ('.target ') .trigger ('mousemove ')Optionally you can also specify the coordinates to movemove Example: cy.get (' # divStart ') .trigger ('mousemove ', {clientX: 200, clientY: 300})9. Mouse Leave Events employ Cypress
cy.get (' # image1 ') .trigger ('mouseleave ')10. Cypress scrollIntoView bidding
For example, if you require to scroll the image into vista you can pen the command belowExample: cy.get (' # bottom_image ') .scrollIntoView ()11. Cypress Select command
.select (value)
Example: cy.get (' # yield ') .select ('apple ');
2. The select command can be used to take multiple options at onceHandling Touch Events in Cypress
1. touchstart
cy.get ('selector ') .trigger ('touchstart ', {force: true});2. touchend
cy.get ('selector ') .trigger ('touchend ', {force: true});3. touchmove
cy.get ('selector ') .trigger ('touchmove ', {strength: true});4. touchcancel
cy.get ('selector ') .trigger ('touchcancel ', {force: true});cy.viewport ('iphone-xr ')}) it ('touchstart case demo ', () = & gt; {cy.visit ('https: //patrickhlauke.github.io/touch/tests/event-listener_prevent-default-touchend.html'); cy.wait (3000); cy.get (' # b ') .trigger ('touchstart ')})})Cypress Mouse and Touch Events Best Practices
cy.get (' # somemenu ') .trigger ('click ');cy. (' # input_username ') .focus ();cy.get ('form ') .submit ()cy.get (' [type= '' text ''] ') .clear ()cy.get ('input [type=file1] ') .selectFile ('file.json ')cy.get ('input [type=file1] ') .selectFile (['file.json ', 'file2.json '])Why Use BrowserStack Automate to Run Your Cypress Tests?
Conclusion
Utilitarian Resources for Cypress
Related Guides
Automate This With SUSA
Test Your App Autonomously