The Search/startsWith extension evaluates elements found by an XPath query and checks whether each element text starts with the provided value.
This is useful when a journey needs to validate that table rows, list items, or other page text values begin with an expected character or prefix before continuing with later checks.
Parameters:
-
xpathInputrequired, a string containing the XPath query used to locate elements in the current document; -
startingValuerequired, a string containing the prefix that each extracted text value should start with. The script converts this value to lowercase before comparison;
Note: The comparison is case-insensitive because both the extracted text and startingValue are converted to lowercase before startsWith is evaluated.
NLP usage
Use the extension in a journey by calling Search/startsWith with the execute command. Pass each value to the matching extension input using as inputName.
Note: If any extracted value does not start with the selected prefix, the extension throws an error listing the mismatched values.
execute "Search/startsWith" using "(//table[@id='customers']//tbody//tr[position() > 1])" as xpathInput using "g" as startingValue returning $statusexecute "Search/startsWith" using "//ul[@id='names']//li" as xpathInput using "a" as startingValue returning $statusYou can also pass stored variables into the extension inputs.
execute "Search/startsWith" using "$targetXpath" as xpathInput using "$expectedStart" as startingValue returning $statusstore value "(//table[@id='customers']//tbody//tr[position() > 1])" in $targetXpath
store value "g" in $expectedStart
execute "Search/startsWith" using "$targetXpath" as xpathInput using "$expectedStart" as startingValue returning $statusExample output when all extracted values start with the expected value:
{
"extractedData": [
{
"extractedText": "green"
},
{
"extractedText": "gold"
}
],
"matchedElements": [
"green",
"gold"
],
"mismatchedElements": [],
"summary": "All values start with selected alphabet: true"
}This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: The script depends on browser DOM XPath support and can only inspect elements available in the current document. It lowercases extracted text before returning it, so the returned arrays do not preserve original casing. It does not trim or normalize the startingValue input, and it throws an error instead of returning a structured mismatch object when mismatches are found.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 25/05/2026
Resources:
This extension does not require any external resource.
// Note this extension is not a product feature of Virtuoso and is not officially supported
// Extensions use javascript which may or may not be compatible with systems under test (SUTs)
// We welcome you to use this extension or adapt it for your needs
let xpath = xpathInput; // Your XPath
let searchText = startingValue.toLowerCase(); // Your partial text, converted to lowercase
let results = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
let matchedElements = [];
let mismatchedElements = [];
let extractedData = [];
for (let i = 0; i < results.snapshotLength; i++) {
let element = results.snapshotItem(i);
let cellText = (element.textContent || element.innerText).trim().toLowerCase();
extractedData.push({ "extractedText": cellText });
if (cellText.startsWith(searchText)) {
matchedElements.push(cellText);
} else {
mismatchedElements.push(cellText);
}
}
let allValuesStartWithText = matchedElements.length === results.snapshotLength;
if (!allValuesStartWithText) {
// Format the mismatched elements into a bullet list
let formattedMismatchedElements = mismatchedElements.map(el => `- ${el}`).join('\n');
let errorMessage = `Mismatch found:\n${formattedMismatchedElements}`;
throw new Error(errorMessage);
}
return {
extractedData: extractedData,
matchedElements: matchedElements,
mismatchedElements: mismatchedElements,
summary: "All values start with selected alphabet: " + allValuesStartWithText
};
Comments
0 comments
Please sign in to leave a comment.