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.
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
Other conditions:
has_attr()
,
has_css_property()
,
has_length()
,
has_name()
,
is_enabled()
,
is_present()
,
is_visible()
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"), "")