Capture a value to a string

You can capture a string that is embedded in the HTML by using object identification. For example, sending an input value back to the server or writing it as a user defined data point.

Try it out!

The following table summarizes the pages and scripts used in the example:

Example description HTML pages Page Description Example scripts
Extract a number from HTML and report it to the Vuser log as a user defined data point. dynamic_value.html Generates a random number

The following example demonstrates how to capture the string and to write it to the log file and to a data point using either the Descriptors or the JavaScript ID method.

  1. Record the following steps:

    1. Navigate to the dynamic_value.html page.
    2. Click the Generate button.
    3. Stop recording.
  2. Click Step in the toolbar, select Miscellaneous, add an Evaluate JS on Object step and select the No. <Value> step as the object.

  3. In the Object section, change the ID method of the No.<Value> step.

  4. Edit the Arguments section by adding the following code:

    Copy code
    var text = object.textContent;   //object holds the DOM object that you previously found
    var index = text.indexOf(". ");   //The indexOf() method returns the position of the first occurrence of a specified value in a string.
    var randomText = text.substr(index+2);
    TC.log("Captured String: " + randomText,"Standard");


  5. Click Step in the toolbar, select Miscellaneous and drag and drop an Evaluate JavaScript step into the script.

  6. In the Arguments section add the following code:


  7. Check the logs to verify that the string was captured.

Back to top