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>

</head>

<body class="template">

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

Sample text

</h1>

</body>

</html>

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

window.alert(textValue);

Advertisements

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

  1. Ganesh

    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?

    Thanks,
    Ganesh

    Reply
  2. Helan

    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?

    Reply
  3. keerthi prabha

    Hi Abdul Sir,
    Thank you so much for your post.
    But while replying the below step. am getiing error.
    window.alert(textValue);

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

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s