LoadRunner Support Forum
Showing results for 
Search instead for 
Do you mean 

TC_FF: evalXPath will not evaluate variable inside of for loop

SOLVED
Go to Solution
Esteemed Contributor Esteemed Contributor

TC_FF: evalXPath will not evaluate variable inside of for loop

[ Edited ]

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?

1 ACCEPTED SOLUTIONS
Esteemed Contributor Esteemed Contributor

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

That's it!

 

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

12 REPLIES
Esteemed Contributor Esteemed Contributor

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

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]");

 

Esteemed Contributor Esteemed Contributor

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

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.

Esteemed Contributor Esteemed Contributor

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

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.

Trusted Contributor

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

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,

 

 

Esteemed Contributor Esteemed Contributor

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

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.

Esteemed Contributor Esteemed Contributor

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

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.

Frequent Advisor

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

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.
Esteemed Contributor Esteemed Contributor

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

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?

Frequent Advisor

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

[ Edited ]

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.

Highlighted
Esteemed Contributor Esteemed Contributor

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

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.

HPE Expert

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

[ Edited ]

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-P...

 

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.
Esteemed Contributor Esteemed Contributor

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

That's it!

 

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