Skip to contents

has_text() checks that an element's inner text contains a string, while has_exact_text() checks that the inner text only contains the string. Both functions throw an error if the element does not exist in the DOM.

Usage

has_text(x, text)

has_exact_text(x, text)

Arguments

x

A selenider_element object.

text

A string, used to test the element's inner text.

Value

A boolean value: TRUE or FALSE.

Details

These functions do not implement a retry mechanism, and only test a condition once. Use elem_expect() or elem_wait_until() to use these conditions in tests.

See also

Examples

html <- "
<p>Example text</p>
<p class='empty'></p>
"

session <- minimal_selenider_session(html)

has_text(s("p"), "Example") # TRUE

has_exact_text(s("p"), "Example") # FALSE

has_exact_text(s("p"), "Example text") # TRUE

# has_exact_text() is useful for checking when there is no text,
# since has_text("") will always be TRUE.
has_exact_text(s(".empty"), "")