Ask a Question

Regularexpression during findChild does not seem to work.

sridhar249
Occasional Contributor

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)

 

sridhar249_0-1660591900108.png

 

 

Please help.

1 REPLY 1
rraghvani
Regular Contributor

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.*']..."

cancel
Showing results for 
Search instead for 
Did you mean: