Share this page

# 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 | CaptureStringDescriptors_2.zip CaptureStringJS_2.zip

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.

   Use JavaScript ID Method:

   1. Select JavaScript from the ID method dropdown.

   2. In the JavaScript editor enter the following code:

      `document.getElementById("generated_data");`

   Use Descriptors ID Method:

   1. Select Descriptors from the ID Method dropdown.
   2. Click the Edit button to open the Descriptors editor.

   3. Change the text operator from `equals` to `equalsIgnoreDigits`.

      This method searches for No.<Value> and ignores the number that is generated every time you click Generate

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:

       TC.userDataPoint("JustNumbers",randomText);

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

Back to top
https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1 All View Local Help Center View Online Help Center Version: