lr_xml_find in Loadrunner with Examples

When do you use lr_xml_find?

As this is Loadrunner function, you can use in any protocol that you want to capture a value from XML PATH or XPATH, in my experience I used lr_xml_find in Web Service Protocol and Flex Protocol.

Using this function you can capture values using xPath or Query. There are lot of tools in the online where you can paste your xml and keep your cursor and it will tell you the xpath and you can use that xpath in the script.

Sometimes the Xpath changes dynamically and you should observe the behavior running the script multiple iterations and figure out the right xpath. Even if you have Java version in your PC is different than LGs, the xpath will change sometimes.

lr_xml_get_values is also similar to lr_xml_find, use this function when you want to capture value and use it in the next request.

Example 1:

What is the xpath for the following?

<SayHello><HelloResponse><Message>Hello SoftwareHour!</Message></HelloResponse></SayHello>

If you are not able to find the xpath use this online tool, this is so easy to find Xpath using this website

The answer for the above small XML is /SayHello/HelloResponse/Message/text ()

lr_xml_find (“Xml= {SayHello_101_Response}“,
            “Value=Hello SoftwareHour!“,
            “Query=/SayHello/HelloResponse/Message/text()“,
               LAST);

You can use this example script and run in your VuGen and see how the function works.

Example 2:

The other way of getting the Xpath is through your response in the replay log.

Select the request that you want xpath from the response as show in the below image.

lr_xml_find

And in the replay log, right click and click on get xpath as shown in the image.

Leave a Comment