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