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



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

def value
  if tag_name == 'textarea'
    native.content
  elsif tag_name == 'select'
    if native['multiple'] == 'multiple'
      native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content  }
    else
      option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
      option[:value] || option.content if option
    end
  elsif tag_name == 'input' && %w(radio checkbox).include?(native[:type])
    native[:value] || 'on'
  else
    native[:value]
  end
end

Comments