Loadrunner : Extract text from between two html tags using web_reg_save_param or similar

2.1k views Asked by At

I have a snippet of html like this

<strong>




            7834



                         </strong>

I need to extract the value 7834 -and use it in a form. The number is always different, so I can't just hardcode it. The spaces are generated by tabs on the line where the number is and new lines above and below the line where the number is

I've tried the below but both return FAIL (i.e not found in the body)

web_reg_save_param("magicnumber",
    "LB=<strong>",
    "RB=</strong>",
    "Ord=1",
    "SaveLen=4",
    "NotFound=ERROR",
    "Search=All",
    LAST);

web_reg_save_param_regexp(
    "ParamName=magicnumber",
    "RegExp=<strong>(.*?)</strong>",
    "Ordinal=1",
    SEARCH_FILTERS,
    "Scope=Body",
    LAST); 
2

There are 2 answers

1
James Pulley On

You likely have some embedded carriage. return line feed and tab characters that you could use as part of your left and right boundary conditions. Just because you cannot see it, doesn't mean that you cannot include it \r\n\t....

web_reg_save_param("foo",
"LB=<strong>\n\n\n\n\n\n\t\t",
"RB=\n\n\n\n\n\n\t\t\t</strong>",
"ORD=1",
LAST);
2
JosefScript On
"RegExp=<strong>[^a-zA-Z0-9]*([0-9]+)[^a-zA-Z0-9]*<\/strong>"

OK, according to http://lrhelp.saas.hp.com/en/latest/help/function_reference/Content/web/etc/lrFr_web_regular_expessions.htm regex in loadrunner does not support character classes (like '\d' for digit or '\s' for space/tab), so I changed the expression to use character ranges [x-y] and negated ranges [^x-y].

Some regex flavours like to have the forward slash escaped by a backslash (perl, javascript).