Article Overview:
This article will cover how you can achieve the following:
Perform a click action on an element using a custom extension when the native mouse click NLP is not compatible with the AUT.
Problem Statement:
If the Native Mouse click NLP in Virtuoso is not compatible with the AUT, making it difficult to perform a click action during test execution.
Solution:
-
Using Virtuoso's Native Mouse Action NLP: The standard command to perform mouse actions in Virtuoso is: mouse click "Element" If the AUT supports this command, it will execute the click action on the specified element.
-
Custom Extension for Click Action: If the native click NLP is incompatible, you can use the following custom JavaScript extension to simulate the click action:
Extension:
function ClickByXPath(xpath) {
const element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (element) {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
element.dispatchEvent(event);
} else {
console.error('Element not found for the provided XPath.');
}
}
return ClickByXPath(xpath);
-
Usage:
- Step 1: Identify the XPath of the element you wish to click on.
- Step 2: Pass the XPath into the code using the extension parameter ExtClick(xpath).
- Step 3: Call the ExtClick extension into the journey to perform the click action.
- Optional: To perform a double click, use the mouse event as 'dblclick' on line 4 of the code above.
Examples:
Here's how we call the specific extension:
Comments
0 comments
Please sign in to leave a comment.