diff --git a/lib/capybara/node/simple.rb b/lib/capybara/node/simple.rb index fcd03102..d55b410f 100644 --- a/lib/capybara/node/simple.rb +++ b/lib/capybara/node/simple.rb @@ -82,6 +82,8 @@ module Capybara 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 diff --git a/lib/capybara/rack_test/form.rb b/lib/capybara/rack_test/form.rb index c55ee88b..31c55ae4 100644 --- a/lib/capybara/rack_test/form.rb +++ b/lib/capybara/rack_test/form.rb @@ -28,7 +28,10 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node case field.name when 'input' if %w(radio checkbox).include? field['type'] - merge_param!(params, field['name'].to_s, field['value'].to_s) if field['checked'] + if field['checked'] + node=Capybara::RackTest::Node.new(self.driver, field) + merge_param!(params, field['name'].to_s, node.value.to_s) + end elsif %w(submit image).include? field['type'] # TO DO identify the click button here (in document order, rather # than leaving until the end of the params) diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index 06c6c08f..e576fe75 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -67,6 +67,16 @@ Capybara::SpecHelper.spec "node" do @session.find('//textarea[1]').set("some html here") @session.find('//textarea[1]').value.should == "some html here" end + + it "defaults to 'on' for checkbox" do + @session.visit('/form') + @session.find('//input[@id="valueless_checkbox"]').value.should == 'on' + end + + it "defaults to 'on' for radio buttons" do + @session.visit('/form') + @session.find('//input[@id="valueless_radio"]').value.should == 'on' + end end describe "#set" do