Forum Discussion

sharmaankit's avatar
sharmaankit
New Contributor
5 years ago
Solved

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);
}
}
  • sharmaankit's avatar
    sharmaankit
    5 years ago

    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 one

     

    This is the updated regex

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

3 Replies

    • sharmaankit's avatar
      sharmaankit
      New Contributor

      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 one

       

      This is the updated regex

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