Method: Capybara::Node::Element#text
- Defined in:
- lib/capybara/node/element.rb
#text(type = nil, normalize_ws: false) ⇒ String
Retrieve the text of the element. If ignore_hidden_elements
is true
, which it is by default, then this will return only text
which is visible. The exact semantics of this may differ between
drivers, but generally any text within elements with display:none
is
ignored. This behaviour can be overridden by passing :all
to this
method.
58 59 60 61 62 |
# File 'lib/capybara/node/element.rb', line 58 def text(type = nil, normalize_ws: false) type ||= :all unless .ignore_hidden_elements || .visible_text_only txt = synchronize { type == :all ? base.all_text : base.visible_text } normalize_ws ? txt.gsub(/[[:space:]]+/, ' ').strip : txt end |