Ask a Question

Unable to search objects using Regex in scripts

SOLVED
sharmaankit
New Contributor

Unable to search objects using Regex in scripts

I have been working with Regex in scripts and trying to search for all the links on the page which starts with same unique string.  Below code is returning zero objects but if i use an (*) at the end, it is displaying the results. i have another complicated scenario where i cannot work (*) and have to use regex, but i am wondering for this simple regexp expression why the objects are not searching. Below is the code:

function Test()
{ 
let parentObj, hrefRegex, props, values, modLinks;
Sys.Browser("chrome").BrowserWindow(0).Activate();
let page = Sys.Browser("chrome").Page("*");
new CustomObject(page, Tool_Bar.GoToBtn, "Tool_Bar.GoToBtn", 20).get_Object().click();
parentObj = new CustomObject(page, Tool_Bar.ModuleTable, "Tool_Bar.ModuleTable", 20).get_Object()
Log.Message("MenuTable Exists: " + parentObj.Exists);
props = ["ObjectType", "namePropStr"];
values = ["Link", "regexp:^javascript: topLevelMenus\['shared'\].menuClick.*"];
modLinks = parentObj.FindAllChildren(props, values, 100);
Log.Message(modLinks.length);
for(let i = 0; i < modLinks.length; i++) {
Log.Message(modLinks[i].href);
}
}
3 REPLIES 3
TanyaYatskovska
SmartBear Alumni (Retired)

Hi @sharmaankit,

 

Have you checked if this regular expression returns the desired value on different online systems, like: http://regexstorm.net/tester ?

 

 

Also, I suggest that you test how EvaluateXPath works for you.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Thanks Tanya,

Regex was fine and i figured it out that if i use  "Non-Native Regular Expressions" i need to use doube slash instead of oneCapture.PNG

 

This is the updated regex

"regexp:^javascript&colon; topLevelMenus\\['shared'\\].menuClick.*?"

TanyaYatskovska
SmartBear Alumni (Retired)

Thanks for sharing the solution with us, @sharmaankit!

 

 

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



cancel
Showing results for 
Search instead for 
Did you mean: