Method: Capybara::Node::Matchers#has_text?
- Defined in:
- lib/capybara/node/matchers.rb
#has_text?(type, text, **options) ⇒ Boolean #has_text?(text, **options) ⇒ Boolean Also known as: has_content?
Checks if the page or current node has the given text content, ignoring any HTML tags.
By default it will check if the text occurs at least once, but a different number can be specified.
page.has_text?('lorem ipsum', between: 2..4)
This will check if the text occurs from 2 to 4 times.
Overloads:
-
#has_text?(type, text, **options) ⇒ Boolean
Parameters:
-
type
(:all, :visible)
—
Whether to check for only visible or all text. If this parameter is missing or nil then we use the value of ignore_hidden_elements, which defaults to
true
, corresponding to:visible
. -
text
(String, Regexp)
—
The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.
Options Hash (**options):
-
:count
(Integer)
— default:
nil
—
Number of times the text is expected to occur
-
:minimum
(Integer)
— default:
nil
—
Minimum number of times the text is expected to occur
-
:maximum
(Integer)
— default:
nil
—
Maximum number of times the text is expected to occur
-
:between
(Range)
— default:
nil
—
Range of times that is expected to contain number of times text occurs
-
:wait
(Numeric)
—
Maximum time that Capybara will wait for text to eq/match given string/regexp argument. Defaults to default_max_wait_time.
-
:exact
(Boolean)
—
Whether text must be an exact match or just substring. Defaults to exact_text.
-
:normalize_ws
(Boolean)
— default:
false
—
When
true
replace all whitespace with standard spaces and collapse consecutive whitespace to a single space
-
type
(:all, :visible)
—
-
#has_text?(text, **options) ⇒ Boolean
Parameters:
-
text
(String, Regexp)
—
The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.
Options Hash (**options):
-
:count
(Integer)
— default:
nil
—
Number of times the text is expected to occur
-
:minimum
(Integer)
— default:
nil
—
Minimum number of times the text is expected to occur
-
:maximum
(Integer)
— default:
nil
—
Maximum number of times the text is expected to occur
-
:between
(Range)
— default:
nil
—
Range of times that is expected to contain number of times text occurs
-
:wait
(Numeric)
—
Maximum time that Capybara will wait for text to eq/match given string/regexp argument. Defaults to default_max_wait_time.
-
:exact
(Boolean)
—
Whether text must be an exact match or just substring. Defaults to exact_text.
-
:normalize_ws
(Boolean)
— default:
false
—
When
true
replace all whitespace with standard spaces and collapse consecutive whitespace to a single space
-
text
(String, Regexp)
—
Returns:
-
(Boolean)
—
Whether it exists
738 739 740 |
# File 'lib/capybara/node/matchers.rb', line 738 def has_text?(*args, **options) make_predicate(options) { assert_text(*args, **options) } end |