Absent Member.. James Leatherma Absent Member..
Absent Member..
2415 views

TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Suppose I have an XPath like this:

evalXPath("(//a[text()=\"2\"])[1]");

Success! Object found.
 

 

Now suppose I variablize it:

var q=2;
evalXPath("(//a[text()=\""+q+"\"])[1]");

Success! Object found.

 

 

Now suppose I wrap it in a for loop:

For (var q=1; q<8; q++)
evalXPath("(//a[text()=\""+q+"\"])[1]");

FAIL


Why?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

That's it!

 

Vesela, thank you for carefully researching the issue and replying only when you had the correct answer.

0 Likes
12 Replies
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

And just in case you are wondering, even setting a totally different variable inside the loop doesn't help  - it still won't evaluate:

var w = 1;
evalXPath("(//a[text()=\""+w+"\"])[1]");

 

0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Upon further review, variables will not evaluate if the object is inside of ANYthing. If block, For block, Function block, anything. As soon as you take it out of the block, it works fine.

0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Am I missing something here? Right now I have to use 

var iteration = ArgsContext.LR.getParam("Iteration");

 to identify my object, then loop using the entire Action.

0 Likes
AlexisB Absent Member.
Absent Member.

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Hi James,

 

Please let us know what is the current version of LoadRunner?

 

I need to investigate about this and let you know about any valuable information.

 

Kind Regards,

 

 

0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Yes, this is LR12.

It seems to be happening when you drop a For Loop in from the Toolbar, then drop steps in. I finally got it to work if you select a block of steps and right-click and surround with a For Loop.

0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

My mistake - it wasn't an evalXPath, it was just a regular variable substution.

Yeah, this is broken, pretty sure. I used to be able to do this.

If someone can disprove me and tell me how stupid I am being, I will be gracious. But I need this to work, fast.

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution
To set a dynamic value in evalXPath, please use ArgsContext.LR.getParam.

If you wanna set For (var q=1; q<8; q++), it won't work.
0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

So, what youre saying is:

 

1. Set up a for loop *which uses a perfectly accessible variable*

2. Instantiate a LoadRunner parameter

3. Set that parameter to 1

4. Perform the steps

5. Increment the parameter manually

6. Finish the loop

 

Is that what we are saying here?

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Please create a parameter with a set of values (like 1,2,3,4...), change the Update value on to "Each Occurrece", loop the step which has evalXPath.

 

Please check the sample script, it may help.

0 Likes
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

There is NO REASON to do this.

This worked in 11.52. I used for loops frequently.

 

Please investigate and write a bug report or provide me a JavaScript workaround.

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

Hi James,

 

Have you tried using ArgsContext.i where i is the variable used in the for loop. 

 

I have made some test in my LoadRunner 12 environments with the following line of code and I do not receive error messages.

 

evalXPath("//td[text()=\""+ArgsContext.i+"\"]");

 

In your case it should be

evalXPath("(//a[text()=\""+ArgsContext.q+"\"])[1]");

if  in the for loop you are using q as an iteration variable.

 

 

Please make sure that you are using only English letters in the function as it can also cause issues.
Please see the following thread

http://h30499.www3.hp.com/t5/LoadRunner-Support-Forum/Truclient-How-to-parameterize-an-Object-Name-Path/m-p/6515394#M9726

 

Please try it and let us know the outcome.

Thank you in advance.

 

Kind regards,

Vesela

HPE Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
0 Likes
Highlighted
Absent Member.. James Leatherma Absent Member..
Absent Member..

Re: TC_FF: evalXPath will not evaluate variable inside of for loop

Jump to solution

That's it!

 

Vesela, thank you for carefully researching the issue and replying only when you had the correct answer.

0 Likes
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.