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:
-
TestComplete analyzes the object’s DOM child nodes and finds all text nodes among them (that is, nodes with
nodeNameequal to #text). -
For each text node, TestComplete gets the node contents (the
nodeValueproperty 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.
-
-
The resulting values (except for empty values) are combined via the line feed character:
-
The value of the
vbLfconstant or theChr(10)expression in VBScript. -
\nin JavaScript, JScript, C++Script and C#Script. -
vcl.Chr(10)in Python -
#10 in DelphiScript.
-
Remarks
-
The
contentTextproperty is available only in the Tree web model. -
The
contentTextproperty returns an empty string for Textbox objects (INPUTelements). To get and set their text, use the Text property. -
To get an object’s contents with the HTML markup, use the native
innerHTMLproperty.
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
