I have a link that I need to identify and select based on a parameter - it's the name of a specific customer.
I assign the parameter name to a variable at the beginning of my TruClient script when I assign all my variables...
var custName = LR.getParam('Customer Name');
evalXPath("//a[text()=\"" + custName + "\"]")
...which fails to identify the correct object on the page. However, the following evalXPath statement works just fine every time:
When generate an alert box to show the XPath statement I'm building that's not working, it's identical to the one that is working.
I'd ask my 13-year-old what I'm doing wrong, but he's not handy at the moment. Help?
Solved! Go to Solution.
Sounds like custname did not capture a value. Maybe its placed before the value is captured.
If you are customer you can try posting on our internal forums for more personalized support.
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
Sorry - I didn't make myself clear. My bad.
I'm specifying the value of the 'Customer Name' parameter in the script parameters - it's not being captured. I also threw a window.alert(custName) into the script prior before executing that evalXPath statement to validate that the custName wasn't blank (and also did window.alert(xpath) for that matter to validate that I'd built it correctly).
I should have come back and marked this resolved, since I just found my own question again on a search. From the evalXPath context, it is necessary to use `ArgsContext` to reference global variables in the script. I.e.:
evalXPath("//a[text()=\"" + ArgsContext.custName + "\"]")
will yield the desired results.
I applied the changes suggested by you, however i am getting the error saying. there are so many sich object and loadrunner is not able to identify the object uniquikly.
Waiting for your reply.
Thanks in advance.
Can anyone please explain me the format of the below code. Why we are using " before + sign and "\"after + sign.
This code is working fine for me but i want to know the format for this.
In the example below, green text is JS code, while the red text sections are strings (in this case, an XPath expression).
The blue + signs are concatenating the JS value into the string parameter.
Note that the back-slashes are escaping characters.
Read more about it here: https://www.w3schools.com/js/js_strings.asp
Thanks for the Reply.
I have still few doubts can you please calrify it.
Why we dont have backslash(\) after the text XYZ and after the 2nd blue+ sign??
I strongly suggest to learn about string manipulation in JS and specifically the topic of escaping in the link I sent above.