Highlighted
Valued Contributor.
Valued Contributor.
192 views

How to capture value which has long space and newline character in LoadRunner

Jump to solution
<span id="head_lblMagicno"><strong>
  
  
  
  
 2877
 </span>

 

2877 is the dynamic value which needs to be captured. Please guide

 

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: How to capture value which has long space and newline character in LoadRunner

Jump to solution

You might use regular expression to match. Use something like:

 

 

 web_reg_save_param_regexp("ParamName=Magnico", "RegExp=<span id=\"head_lblMagicno\"><strong>[\\s\\n]*(\\d+)");

 

 

The trick is in the parts (ignore surrounding quotes):

  • '[\s\n]*' This search for a sequence of white space '\s' or new lines '\n' of any length '*'.
  • '(\d+)' This match returns any sequence of digits '\d' of at least on digit '+'. It is the the first group between '(...)' so it is returned by default.

Of cause I could not test this in LR, but you can test this at https://regex101.com/

Note:

1 that when you put a regular expression in your C (or Java) code you have to escape each " and \, so that is why those extra \ are in the literal string.

2 Regular expressions are extreme powerful. Learn them well!

Signature:
Reward community members who take time to respond and help.

View solution in original post

2 Replies
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Re: How to capture value which has long space and newline character in LoadRunner

Jump to solution
Hi, if it were me, I'd just capture what is between the less than/greater than signs and then lop off the spaces by using a character pointer to look for the first non-whitespace character. This can be done both forward and backward. Or, once you've found the characters, move the pointer along until it finds whitespace.
Or just convert the string to a number - that might be easiest, actually - I think atoi() will ignore all the whitespace.
As my friends have told me - why use one simple function call when you can write fifty lines of code?
0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: How to capture value which has long space and newline character in LoadRunner

Jump to solution

You might use regular expression to match. Use something like:

 

 

 web_reg_save_param_regexp("ParamName=Magnico", "RegExp=<span id=\"head_lblMagicno\"><strong>[\\s\\n]*(\\d+)");

 

 

The trick is in the parts (ignore surrounding quotes):

  • '[\s\n]*' This search for a sequence of white space '\s' or new lines '\n' of any length '*'.
  • '(\d+)' This match returns any sequence of digits '\d' of at least on digit '+'. It is the the first group between '(...)' so it is returned by default.

Of cause I could not test this in LR, but you can test this at https://regex101.com/

Note:

1 that when you put a regular expression in your C (or Java) code you have to escape each " and \, so that is why those extra \ are in the literal string.

2 Regular expressions are extreme powerful. Learn them well!

Signature:
Reward community members who take time to respond and help.

View solution in original post

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.