Selector.withExactText Method

Selects elements whose text content strictly matches the specified text.

Selector().withExactText(text) → Selector
Argument Type Description
text String The element’s text content. The text argument is case-sensitive.

To search for elements that contain a specific text, use the withText method.


// Selects elements of the 'label' tag
// whose text exactly matches 'I have tried TestCafe'.
// Does not match 'bar', 'foobar', 'Foo'.
const elWithText = Selector('label').withExactText('I have tried TestCafe');


withExactText selects the element that contains the specified text and its ancestors (if they do not contain any other text). For an example, see the following section: withText.

To target elements with HTML symbols or HTML entities (e.g.,  , newline chars), refer to the following section: Select Elements That Contain Special Characters.