class Capybara::Node::Element

def text(type = nil, normalize_ws: false)

Returns:
  • (String) - The text of the element

Parameters:
  • type (:all, :visible) -- Whether to return only visible or all text
def text(type = nil, normalize_ws: false)
  type ||= :all unless session_options.ignore_hidden_elements || session_options.visible_text_only
  txt = synchronize { type == :all ? base.all_text : base.visible_text }
  normalize_ws ? txt.gsub(/[[:space:]]+/, ' ').strip : txt
end