Forum Discussion

sridhar249's avatar
sridhar249
Occasional Contributor
2 years ago

Regularexpression during findChild does not seem to work.

Hi,

 

I am trying to find a Panel on the page with the following outerHTML.

 

 

<div role="group" aria-roledescription="offer" aria-label="Fibre+ Gig Plan Card" class="c-card c-card--odd-number-of-cards">

 

 

 

Here is the regular expression that works.

 

 

page.findChild(['ObjectType', 'className', 'outerHTML'],['Panel', 'c-card*', 'regexp:<div role="group" aria-roledescription="offer" aria-label="Fibre+.*'],100)

 

 

 

Here is the regular expression that does not work: (notice the space after Fibre+)

 

 

page.findChild(['ObjectType', 'className', 'outerHTML'],['Panel', 'c-card*', 'regexp:<div role="group" aria-roledescription="offer" aria-label="Fibre+ .*'],100)

 

 

 

i even tried the following, but no luck. (notice that i used \b instead of the space. According to the documentation here Regular Expressions Syntax | TestComplete Documentation (smartbear.com) \b Matches a whitespace character. I even tried \s instead of \b but no luck.) So, the following did not work.

 

 

page.findChild(['ObjectType', 'className', 'outerHTML'],['Panel', 'c-card*', 'regexp:<div role="group" aria-roledescription="offer" aria-label="Fibre+(\b).*'],100)

 

 

page.findChild(['ObjectType', 'className', 'outerHTML'],['Panel', 'c-card*', 'regexp:<div role="group" aria-roledescription="offer" aria-label="Fibre+(\s).*'],100)

 

 

 

Please help.

1 Reply

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The plus '+' will match one or more consecutive 'e' characters.

     

    function testit()
    {
        var str = "<div role=\"group\" aria-roledescription=\"offer\" aria-label=\"Fibre+ Gig Plan Card\" class=\"c-card c-card--odd-number-of-cards\">";
        //var regEx = /Fibre+ Gig Plan Card/;       // Not working because of '+'
        var regEx = /Fibre\+\s.*/;                  // Working because of '\+'    
    
        var matches = str.match(regEx);
        if (matches != null)
            Log.Message("Found: '" + matches + "'");
        else
            Log.Message("Not found");
    }

     

    Use '\+' followed by '\s' in "...-label="Fibre\+\s.*']..."