Self-Solve Knowledge Search

Minimize Maximize
How to save visible text in a variable in Ajax TruClient protocol in LoadRunner ...
Title :
How to save visible text in a variable in Ajax TruClient protocol in LoadRunner 11.5x and 12
Document ID :
KM00884055
Product - Version:
performance center 11.52 12.00 ; loadrunner 11.52 12.00 ;
OS :
Updated :
Mon Jul 28 10:12:42 GMT 2014
Summary :
Describes how to save visible text in a variable in Ajax TruClient protocol in LoadRunner 11.5x and 12 using Get property step or by writing custom JavaScript code in Evaluate JavaScript step.
How to save visible text in a variable in Ajax TruClient LoadRunner 11.5x and 12 which can be used later in the script?
Solution

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>
</head>
<body class="template">
    <h1 id="pageTitle" class="status1">
        Sample text                        
    </h1>
</body>

</html>

The two approaches are described below:

  1. To write custom JavaScript in a Evaluate JavaScript step
    1. Add Evaluate JavaScript step
    2. In Argument text field enter the following code to save Sample text to the variable  “textValue”

      var textValue= window.document.getElementById("pageTitle").textContent;
      image text
  2. To use Get property step for saving  visible text in a variable:
    1. Add Evaluate JavaScript on Object step
    2. Click on “Click to choose an object” button and select the target text in the web page i.e Sample text
    3. Click on Evaluate JavaScript[Code]
    4. In Step ->Action drop down list select “Get Property”
      image text
    5. In Arguments > Property  drop down list select “Visible Text”
    6. In Arguments > Variable write the name of the variable which will store the value of the visible text, for example “textValue”
      image text

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

    1. For example it can be shown as a JavaScript alert.
    2. Add Evaluate JavaScript step.
      Click on Code and in In Arguments -> Code write
      window.alert(textValue);