contentText Property (Web Objects)

Applies to TestComplete 15.62, last modified on March 14, 2024

Description

The contentText property returns the combined text of a web page object and its child objects.

It is similar to the native innerText property in Internet Explorer or Edge and the textContent property in Firefox, or Chrome. However, innerText and textContent differ in whitespace representation and child node contents included, so the TestComplete contentText property serves as a cross-browser analog of these properties. You should use the contentText property instead of innerText and textContent in your tests, checkpoints and Name Mapping identification properties.

Declaration

TestObj.contentText

Read-Only Property String
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

The property is applied to the following object:

View Mode

This property is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Property Value

A string containing the combined text content of the object and all of its child objects. This text includes visible elements as well as hidden ones, that is, elements with style.display="none" or style.visibility="hidden".

TestComplete generates the contentText property value in the following way:

  1. TestComplete analyzes the object’s DOM child nodes and finds all text nodes among them (that is, nodes with nodeName equal to #text).

  2. For each text node, TestComplete gets the node contents (the nodeValue property value) and processes it as follows:

    • Replaces subsequent whitespace characters (spaces, tabs, non-breaking spaces, line breaks and so on) with a single space.

    • Trims whitespace at the beginning and the end of the value.

  3. The resulting values (except for empty values) are combined via the line feed character:

    • The value of the vbLf constant or the Chr(10) expression in VBScript.

    • \n in JavaScript, JScript, C++Script and C#Script.

    • vcl.Chr(10) in Python

    • #10 in DelphiScript.

Remarks

  • The contentText property is available only in the Tree web model.

  • The contentText property returns an empty string for Textbox objects (INPUT elements). To get and set their text, use the Text property.

  • To get an object’s contents with the HTML markup, use the native innerHTML property.

Example

Consider the following HTML code:

HTML

<div>
  <p>Sample list:</p>
  <ul>
    <li>List <i>item 1</i></li>
    <li>List <a href="http://smartbear.com">item <b>2</b></a></li>
  </ul>
</div>

The contentText property of the Panel object corresponding to the DIV element returns the following value:

Sample list:
List
item 1
List
item
2

See Also

Classic Web Testing
Text Property (Web Objects)

Highlight search results