In a nutshell
The Hover and Click task hovers over a web element during test execution, then clicks the same element or another element revealed by the hover. Use it to automate interactions where a click depends on a preceding hover, such as selecting a quick-view button or a hover-revealed menu item.
The Hover and Click task hovers the mouse pointer over an element, then performs a click, either on that same element or on a different one, in a single task call. It's commonly used to confirm scenarios such as a hover-revealed button, menu item, or link that needs to be clicked as part of the same interaction.
The Hover and Click task can be used in two ways:
Follow the Hover and Click task with an appropriate assertion task, such as Assert Visible or Assert Text, to verify the expected result.
To hover over an element and click that same element:
hoverAndClick(<locator>);
| Parameter | Data Type | Description |
| locator | STRING | Identifies the element to hover over and then click. Note: Locators can be found by manually inspecting the webpage for the element, or by using an element already saved through a recording session. Learn more about Elements |
hoverAndClick(<hover_locator>, <click_locator>);
| Parameter | Data Type | Description |
| hover_locator | STRING | Identifies the element to hover over. |
| click_locator | STRING | Identifies the element to click after hovering, which may be different from the hovered element. |
Verify that hovering over and clicking the Add to Cart button adds the product to the cart.
// Open the Diver Chronomat product page on the ZWatch Commerce website using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722", "same window");
// Hover over and click the Add to Cart button using the Hover and Click task
hoverAndClick(".theme-product-qty-and-add-cart");
// Confirm the cart success message appears using the Assert Visible task
assertVisible(".theme-cart-add-success-message", errorhandling.STOP_ON_ERROR);where:
| "https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722" | Diver Chronomat product page URL. |
| "same window" | Opens the page in the window already running the test. |
| .theme-product-qty-and-add-cart | Locator for the Add to Cart button. |
| .theme-cart-add-success-message | Locator for the cart confirmation message. |
| errorhandling.STOP_ON_ERROR | Stops the test case if the cart confirmation message isn't visible. |
Hovering over a product card reveals a Quick View button that can be clicked without opening the product page.
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Click the link to the shop page using the Click task
click("a[href*='all-products']");
// Hover over the Diver Chronomat product link, then click its quick-view button, using the Hover and Click task
hoverAndClick("a[href='/products/diver-chronomat/3531661000000075722']", "[data-zs-product-url='/products/diver-chronomat/3531661000000075722']");
// Confirm the quick-view overlay is visible using the Assert Visible task
assertVisible(".theme-quick-view-container", errorhandling.STOP_ON_ERROR);where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| a[href*='all-products'] | Locator for the link to the shop page. |
| a[href='/products/diver-chronomat/3531661000000075722'] | Locator for the Diver Chronomat product link, the element to hover over. |
| [data-zs-product-url='/products/diver-chronomat/3531661000000075722'] | Locator for the Diver Chronomat quick-view button, revealed by the hover and then clicked. |
| .theme-quick-view-container | Locator for the quick-view overlay. |
| errorhandling.STOP_ON_ERROR | Stops the test case if the quick-view overlay isn't visible. |
On a Facility Booking application's Rooms page, hovering over a room card reveals an Edit button that can be clicked in the same action.
// Open the Rooms page in a Zoho Creator Facility Booking application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/facility-booking#Page:Rooms", "same window");
// Hover over the room card, then click its Edit button, using the Hover and Click task
hoverAndClick(ui.facilitybooking.room-card, ui.facilitybooking.room-edit-button);
// Confirm the room edit form is visible using the Assert Visible task
assertVisible(ui.facilitybooking.room-edit-form, errorhandling.STOP_ON_ERROR);where:
| "https://creatorapp.zoho.com/<orgname>/facility-booking#Page:Rooms" | URL of the Rooms page in a Zoho Creator Facility Booking application. |
| "same window" | Opens the page in the window already running the test. |
| ui.facilitybooking.room-card | Locator for the room card, the element to hover over. |
| ui.facilitybooking.room-edit-button | Locator for the Edit button, revealed by the hover and then clicked. |
| ui.facilitybooking.room-edit-form | Locator for the room edit form. |
| errorhandling.STOP_ON_ERROR | Stops the test case if the room edit form isn't visible. |
Shoppers browsing the shop page often preview a product and add it to the cart without opening the full product page, and the hover-to-reveal quick-view button needs to lead into that flow correctly.
A tester uses Zoho QEngine to confirm that hovering over a product and clicking its quick-view button opens the overlay. The test then verifies that adding the item to the cart from within the overlay works correctly.
Implementation
// Step 1: Open the ZWatch Commerce home page in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the link to the shop page using the Click task
click("a[href*='all-products']");
// Step 3: Hover over the Diver Chronomat product link, then click its quick-view button, using the Hover and Click task
hoverAndClick("a[href='/products/diver-chronomat/3531661000000075722']", "[data-zs-product-url='/products/diver-chronomat/3531661000000075722']");
// Step 4: Add the product to the cart from within the quick-view overlay using the Click task
click(".theme-quick-view-container .theme-product-qty-and-add-cart");
// Step 5: Confirm the cart success message appears using the Assert Visible task
assertVisible(".theme-cart-add-success-message", errorhandling.STOP_ON_ERROR);Shoppers hovering over different products expect the quick-view overlay to open for the one they hovered over, not a different product left over from an earlier preview.
A tester uses Zoho QEngine to confirm that hovering over the Navitimer product and clicking its quick-view button in one action opens an overlay showing the Navitimer product.
Implementation
// Step 1: Open the ZWatch Commerce home page in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the link to the shop page using the Click task
click("a[href*='all-products']");
// Step 3: Hover over the Navitimer product link, then click its quick-view button, using the Hover and Click task
hoverAndClick("a[href='/products/navitimer/3531661000000075776']", "[data-zs-product-url='/products/navitimer/3531661000000075776']");
// Step 4: Confirm the quick-view overlay displays the Navitimer name using the Assert Text task
assertText(".theme-quick-view-container .theme-product-name-area", "Navitimer", errorhandling.STOP_ON_ERROR);Consider a Zoho Creator Facility Booking application that facility staff use to manage meeting room reservations. The Facility Overview page displays a room status widget built in Page Builder. Staff hover over the widget to reveal a View Booking History link, then click it to open the room's booking history, rather than navigating there through a separate menu.
A tester uses Zoho QEngine to confirm that hovering over the room status widget and clicking the revealed link navigates to the correct booking history.
Implementation
// Step 1: Open the Facility Overview page in a Zoho Creator Facility Booking application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/facility-booking#Page:Facility_Overview", "same window");
// Step 2: Wait until the room status widget is present
wait(10, ui.facilitybooking.room-status-widget, event.PRESENT);
// Step 3: Hover over the room status widget, then click the View Booking History link, using the Hover and Click task
hoverAndClick(ui.facilitybooking.room-status-widget, ui.facilitybooking.view-booking-history-link);
// Step 4: Confirm the booking history report is visible using the Assert Visible task
assertVisible(ui.facilitybooking.booking-history-report, errorhandling.STOP_ON_ERROR);7. What's next
Now that you've learned how to hover over an element and click it in one action using the Hover and Click task, learn how to scroll to a specific position or element using the Scroll To task.
Before using the Hover and Click task, ensure you have learned how to hover over an element using the Hover task.