Re: TC_FF: evalXPath will not evaluate variable inside of for loop (669 Views)
Reply
Esteemed Contributor
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 1 of 13 (891 Views)
Accepted Solution

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?

Esteemed Contributor
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 2 of 13 (873 Views)

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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 3 of 13 (859 Views)

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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 4 of 13 (821 Views)

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
AlexisB
Posts: 124
Registered: ‎04-10-2013
Message 5 of 13 (814 Views)

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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 6 of 13 (809 Views)

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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 7 of 13 (793 Views)

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.

Advisor
Bach
Posts: 22
Registered: ‎01-22-2014
Message 8 of 13 (783 Views)

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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 9 of 13 (749 Views)

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?

Advisor
Bach
Posts: 22
Registered: ‎01-22-2014
Message 10 of 13 (742 Views)

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.

Esteemed Contributor
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 11 of 13 (725 Views)

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.

HP Expert
vmanolova
Posts: 536
Registered: ‎05-24-2012
Message 12 of 13 (709 Views)

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

HP 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
James Leatherman
Posts: 543
Registered: ‎06-05-2008
Message 13 of 13 (669 Views)

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.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.