How to save visible text in a variable in Ajax TruClient protocol in LoadRunner 11.5x and 12

There are two possible approaches to save visible text in a variable: by using Get property step or by writing custom JavaScript in Evaluate JavaScript step.

The sample code below will be used as to demonstrate how to save the visible text “Sample text” in h1 tag in the variable “textValue” using these two approaches:

<!DOCTYPE html>

<html >

<head >

<title>Dynamic Data Site</title>


<body class="template">

<h1 id="pageTitle" class="status1">

Sample text




The two approaches are described below:

To write custom JavaScript in a Evaluate JavaScript step

Add Evaluate JavaScript step

In Argument text field enter the following code to save Sample text to the variable “textValue”

var textValue= window.document.getElementById("pageTitle").textContent;

To use Get property step for saving visible text in a variable:

Add Evaluate JavaScript on Object step

Click on “Click to choose an object” button and select the target text in the web page i.e Sample text

Click on Evaluate JavaScript[Code]

In Step ->Action drop down list select “Get Property”

In Arguments > Property drop down list select “Visible Text”

In Arguments > Variable write the name of the variable which will store the value of the visible text, for example “textValue”

After the value is saved to the variable it can be used later in the script.

For example it can be shown as a JavaScript alert.

Add Evaluate JavaScript step.

Click on Code and in In Arguments -> Code write


READ  Cannot get Window Resources, IIS, SQL, or ASP performance data from the Controller

5 thoughts on “How to save visible text in a variable in Ajax TruClient protocol in LoadRunner 11.5x and 12”

  1. Hi, I have a situation and would like to get your help. I’m using Ajax TruClient protocol to script the QlikView application. There are few list boxes on the page and I’m using “ID Method” as “JavaScript” under “Object” node of the actual step, as I need to select a random value from that drop down. The JavaScript evaluated to evalXPath(“//div[@id=\”MainContainer\”]/div[70]/div[2]/div/div[1]/div[“+window.nEntity+”1]/div[1]”); and everytime the build is deployed the value for div[70] changes and the object is not identified. I need to record the step again and change the value of that 70 to the correct one that shows up on that day.

    Can you tell me how to overcome this situation?


  2. I tried the Evaluate JavaScript on Object option.But is is giving reference error textValue undefined in the subsequent evaluate javascript code step…any idea what might be the reason?

  3. Hi Abdul Sir,
    Thank you so much for your post.
    But while replying the below step. am getiing error.

    Can u please help on this once.
    Error Mesage: giving reference error textValue . varaible is not defined…


Leave a Comment