cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to search objects using Regex in scripts

SOLVED
Highlighted
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);
}
}
1 ACCEPTED SOLUTION

Accepted Solutions
New Contributor

Re: Unable to search objects using Regex in scripts

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.*?"

View solution in original post

3 REPLIES 3
Community Manager

Re: Unable to search objects using Regex in scripts

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 Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Contributor

Re: Unable to search objects using Regex in scripts

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.*?"

View solution in original post

Community Manager

Re: Unable to search objects using Regex in scripts

Thanks for sharing the solution with us, @sharmaankit!

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Top Kudoed Authors