Keyboard and Mouse Actions | Zoho QEngine Help

Keyboard and Mouse Actions

This list of tasks provides methods to simulate various keyboard and mouse interactions.

Keyboard and Mouse Actions tasks include the following:

Double Click 

This task performs a double-click action on an element within a webpage. For example, this task can be used to trigger various interactions that occur with the double-click action, such as opening items or executing specific actions.

Syntax 

doubleClick(<locator>);

 

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the element on which you want to perform the double-click action.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.


Example: A user is testing the product listing page of an ecommerce website. The listing pages should provide customers with the option to view high-resolution images of products by double-clicking on a product image or thumbnail. The following test script allows the user to double-click on an image.

 

  1. doubleClick(ui.zwatch.GMT-product-image);

where:

 

ui.zwatch.GMT-product-image

STRING

The recorded element of the required product image.


Right Click 

This task performs a right-click action on an element within a webpage. For example, this action can be used to trigger various interactions that occur with the right-click action, such as context menus, perform various interactions, and much more.

Syntax 

rightClick(<locator>);

 

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the element on which you want to perform the right-click action.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.


Example: A user is testing the functionality of accessing context menus for products on an ecommerce website. Customers should be able to access a context menu by right-clicking on a product listing. The following test script allows users to right-click on a product to access its context menu.

 

  1. rightClick(ui.zwatch.product-menu);

 

where:

 

ui.zwatch.product-menu

The recorded element to access the context menu of a product.


Send Keys 

The task performs the action of pressing of keys on the physical or virtual keyboard to provide text or special key actions to a web element on a webpage. For example, to automate typing text into a web search bar.

Syntax 

sendKeys(<locator>, <keys>);

 

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the element that should receive the keyboard input.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

<keys>

ARRAYLIST

The task involves specifying an array list containing a sequence of keyboard keys that you want to send to the web element.

 

Possible values: Sequence of characters and special keys such as ADD, ALT, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, BACK_SPACE, CANCEL, CLEAR, COMMAND, CONTROL, DECIMAL, DELETE, DIVIDE, DOWN, END, ENTER, EQUALS, ESCAPE, HELP, HOME, INSERT, LEFT, LEFT_ALT, LEFT_SHIFT, META, MULTIPLY, NULL, PAGE_DOWN, PAGE_UP, PAUSE, RETURN, RIGHT, SEMICOLON, SEPARATOR, SHIFT, SPACE, SUBTRACT, TAB, UP.


Note:
  1. In order to send a sequence of characters as a value, use the format: "<text>" or to send special keys, use the format: keys.<key>
  1. The keys are sent in the order they appear in the parameter.


Example: A user wants to test the login form of an ecommerce website. The user needs to enter their username and password. The following script enables the user to fill the username and password fields, one after the other and ultimately submit the form.

 

  1. sendKeys(ui.zwatch.username-field, ["Sharon Morgan",keys.TAB,"Sharon@zylker",keys.ENTER]);

 

where:

 

ui.zwatch.username-field

The recorded element of the username field in the login form.

["Sharon Morgan",keys.TAB,"Sharon@zylker",keys.ENTER]

The array of keys is sent to fill the username field, then move to the password field and finally submit the form.


Hover 

This task performs the action of hovering the mouse cursor over an element within a webpage. For example, this task can be used to trigger various interactions that occur with hover action such as displaying tooltips, revealing additional information, or navigating dropdown menus that appear when an element is hovered over.

Syntax 

hover(<locator>);

 

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the element to be hovered on.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.


Example: A user wants to test the navigational links on the header in an e-commerce website. The following test script hovers over the link for "Premium Accounts" that gives hover-based preview of the premium account benefits.

 

  1. hover(ui.zwatch.premium-account);

 

where:

 

ui.zwatch.premium-account

The recorded element to access the navigational link for "Premium Accounts".


Hover and Click 

This task performs both hovering the mouse cursor over a webpage element to trigger any related events such as dropdown menus and subsequently clicking on the same element to perform a corresponding action. It can also involve hovering over a webpage element to trigger associated events, then clicking on a different element to perform a related action.

Syntax 

hoverAndClick(<locator>);

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the element that you want to hover the mouse cursor over, then click.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

 

Syntax

hoverAndClick(<hover_locator>, <click_locator>);

 

Parameter

Data Type

Description

<hover_locator>

STRING

Address to locate the element that you want to hover the mouse cursor over.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

<click_locator>

STRING

Address to locate the element on which you want to perform a click action after hovering.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.


Example 1: A user wants to test the header's navigational links on an e-ommerce website. Among these links is one that provides the option to sign up for premium accounts with enhanced features. The following script initiates a hover and click action on the "Premium Accounts" navigational link.

 

  1. hoverAndClick(ui.zwatch.premium-account);

 

where:

 

ui.zwatch.premium-account

The recorded element to access the navigational link for "Premium Accounts".


Example 2: A user wants to test the navigational links on the header in an e-commerce website. The following script initiates hover over the "Influencers Club" link to preview the benefits, then clicks on the "Join Now" button in the preview.

 

  1. hoverAndClick(ui.zwatch.premium-account,ui.zwatch.join-button);

 

where:

 

ui.zwatch.influencer-club

The stored element to access the navigational link for "Influencers Club". 

ui.zwatch.join-button

The stored element of the "Join Now" button inside the preview of the club benefits.


Scroll To 

This task provides distinct methods to navigate a webpage. This can be configured in three ways:
  • Using the element locators, it automates scrolls to a particular element within a webpage, ensuring it comes into view.

  • By specifying "X-axis" and "Y-axis" coordinates, it offers precision in scrolling to exact positions on the page.

  • By specifying positions (Top, Left, Right, and Bottom), it allows flexible scrolling to different parts of the webpage.

  • By specifying the position along with the locator, it automates scroll for a scrollable element of the webpage.


Syntax 

scrollTo(<scroll_input>);

 

 

Parameter

Data Type

Description

<scroll_input>

STRING

This input determines how the scroll behaves on the webpage.

 

The following are the three distinct ways to configure the scroll input:

 

locator: Address to locate the element that you want to scroll to.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

COORDINATES: The horizontal (X-axis) and the vertical (Y-axis) coordinates to which you want to scroll. The X coordinate represents the left-to-right positioning on the webpage. The Y coordinate represents the top-to-bottom positioning on the webpage. It is typically measured in pixels.

 

position.BOTTOM: Scrolls to the bottom of the webpage.


position.CENTER: Scrolls to the center of the webpage.


position.LEFT: Scrolls to the leftmost part of the webpage.


position.RIGHT: Scrolls to the rightmost part of the webpage.


position.TOP: Scrolls to the top of the webpage.

 

In order to scroll to a specified element, use ("locator"), to scroll to an element using their coordinates, use ("x:<point>, y:<point>") or to scroll to a particular position on a webpage, use (<position>).

 


Syntax

scrollTo(<locator>, <position>);

 

Parameter

Data Type

Description

<locator>

STRING

Address to locate the scrollable element on the webpage.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

<position>

STRING

The four scroll positions:

  • position.BOTTOM: Scrolls to the bottom within scroll container.

  • position.CENTERScrolls to the center within the scroll container.

  • position.TOP: Scrolls to the top within the scroll container.

  • position.LEFT: Scrolls to the leftmost part within the scroll container.

  • position.RIGHT: Scrolls to the rightmost part within the scroll container.


Example 1: A user wants to test the scroll functionality of a webpage on an e-commerce website. The users search for and select specific products within large listings on the website. The following script is used to scroll to a product's card.

 

  1. scrollTo(ui.zwatch.GMT-product-card);

 

where:

 

ui.zwatch.GMT-product-card

The recorded element for the product card.

 

 

Example 2: Ecommerce websites often feature promotional banners for special offers or sales. The following script is used to scroll the page to a promotional banner.
 
  1. scrollTo("x:66,y:976");
 
where:

 

"x:66,y:976"

The "x" and "y" coordinates for the promotional banner.


Example 3: Ecommerce websites with extensive product listings may require users to scroll to explore all available items. The following script is used to scroll to the end of the product listing.
 
  1. scrollTo(position.BOTTOM);
 
where:

 

position.BOTTOM

To scroll to the end of the product listing, which is present at the bottom part of the webpage.


Example 4: In an ecommerce website, product reviews play a significant role in influencing purchase decisions. Here, the website is designed with a scrollable product reviews section. The following script is used to scroll to the top reviews within the product review section on the website.
 
  1. scrollTo(ui.zwatch.product-review,position.TOP);
 
where:

 

ui.zwatch.product-review

The recorded element to navigate to the product review section on the website.

position.TOP

To scroll the reviews to the top of the scrollable area.


Drag And Drop 

This task performs the user action of dragging a web element from one location and dropping it onto another location on a webpage.

Syntax 

dragAndDrop(<from_locator>,<to_locator>,<seconds>);

 

 

Parameter

Data Type

Description

<from_locator>

STRING

Address to locate the element to be dragged.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

<to_locator>

STRING

Address to locate the element or the coordinates within the webpage in which it'll be dropped.

 

Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more.

Alternatively, it can take the horizontal (X-axis) and the vertical (Y-axis) coordinates. The X coordinate represents the left-to-right positioning on the webpage. The Y coordinate represents the top-to-bottom positioning on the webpage. Coordinates can be used in the format, ("x:<point>, y:<point>").

<seconds>

LONG

The time duration set to account for the delay when dragging an element from one location and dropping it to another. It is measured in seconds.

 

Note: The time duration must be less than 10 seconds.


Example: A user wants to test the add to cart functionality in an ecommerce website. The website has a drag and drop functionality that allows users to add their desired products to cart. The following script allows the user to drag and drop a product to the cart.

  1. dragAndDrop(ui.zwatch.Dayton,ui.zwatch.cart,10);

where:

ui.zwatch.Dayton

The recorded element to locate the product in the website.

ui.zwatch.cart

The recorded element of the cart in the website.

10

The time the task has to wait for the product to be dragged and dropped into the cart.