The Search/getElementDetails extension evaluates an XPath expression against the current page and returns the matching DOM elements.
This is useful when your test needs to inspect elements that match a specific XPath, count matching elements, or return matching page elements for debugging or follow-up validation.
Parameters:
-
XPathrequired, the XPath expression used to search the current HTML document for matching elements.
Note: The XPath is evaluated against the current document using document.evaluate. Make sure the target elements are already present in the DOM before running the extension.
NLP usage
Use the extension in a journey by calling Search/getElementDetails with the execute command. Pass the XPath value to the matching extension input using as XPath.
Note: If matching elements are found, the extension returns an array of DOM elements. If no matching elements are found, it returns No matching elements found.
To get elements by XPath:
execute "Search/getElementDetails" using "//button" as XPath returning $elementsTo get a specific element by text:
execute "Search/getElementDetails" using "//*[normalize-space()='Submit']" as XPath returning $elementsTo get all input elements on the page:
execute "Search/getElementDetails" using "//input" as XPath returning $elementsYou can also use a Virtuoso variable to make the same step reusable for different XPath expressions:
execute "Search/getElementDetails" using "$xpathExpression" as XPath returning $elementsExample setup using a variable before calling the extension:
store value "//button" in $xpathExpression
execute "Search/getElementDetails" using "$xpathExpression" as XPath returning $elementsExample output when no element matches the XPath:
No matching elements foundThis extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension depends on browser DOM APIs and can only find elements that are available in the current document at execution time. It may not find elements inside closed shadow DOMs, inaccessible iframes, or content that has not yet loaded. Returned DOM elements may also be difficult to serialize or reuse directly as plain text.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 22/05/2026
Resources: None
try {
const xpathExpr = XPath;
const result = document.evaluate(xpathExpr, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
const length = result.snapshotLength;
console.log(length)
const elements = [];
if (length > 0) {
for (let i = 0; i < length; i++) {
const element = result.snapshotItem(i);
elements.push(element);
}
}
else {
return "No matching elements found";
}
console.log(elements)
return elements;
} catch (error) {
throw new Error(`An error occurred: ${error}`);
}
Comments
0 comments
Please sign in to leave a comment.