Method: Capybara::Node::Simple#value

Defined in:
lib/capybara/node/simple.rb

#valueString

Returns The value of the form element.

Returns:

  • (String)

    The value of the form element



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/capybara/node/simple.rb', line 78

def value
  if tag_name == 'textarea'
    native['_capybara_raw_value']
  elsif tag_name == 'select'
    selected_options = find_xpath('.//option[@selected]')
    if multiple?
      selected_options.map(&method(:option_value))
    else
      option_value(selected_options.first || find_xpath('.//option').first)
    end
  elsif tag_name == 'input' && %w[radio checkbox].include?(native[:type])
    native[:value] || 'on'
  else
    native[:value]
  end
end