From 741c31bf2bc6ce8c9ac1af29ea985fa07e09d261 Mon Sep 17 00:00:00 2001 From: Keita Urashima Date: Thu, 20 May 2010 10:31:20 +0900 Subject: [PATCH 1/2] The input element which has no type attributes should be regarded as a text field. --- lib/capybara/xpath.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capybara/xpath.rb b/lib/capybara/xpath.rb index 87e914f29..eb981b75f 100644 --- a/lib/capybara/xpath.rb +++ b/lib/capybara/xpath.rb @@ -111,7 +111,7 @@ def button(locator) def text_field(locator, options={}) options = options.merge(:value => options[:with]) if options.has_key?(:with) - add_field(locator, "//input[@type!='radio' and @type!='checkbox' and @type!='hidden']", options) + add_field(locator, "//input[not(@type) or (@type!='radio' and @type!='checkbox' and @type!='hidden')]", options) end def text_area(locator, options={}) From 37e301200985e6aebc86ab593013c84bbcb58531 Mon Sep 17 00:00:00 2001 From: Keita Urashima Date: Thu, 20 May 2010 20:43:16 +0900 Subject: [PATCH 2/2] Add spec, all specs were made to pass. --- lib/capybara/driver/rack_test_driver.rb | 2 +- lib/capybara/driver/selenium_driver.rb | 2 +- lib/capybara/spec/session/fill_in_spec.rb | 6 ++++++ lib/capybara/spec/views/form.erb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/capybara/driver/rack_test_driver.rb b/lib/capybara/driver/rack_test_driver.rb index 201a5ecb8..f4cc46104 100644 --- a/lib/capybara/driver/rack_test_driver.rb +++ b/lib/capybara/driver/rack_test_driver.rb @@ -112,7 +112,7 @@ class Form < Node def params(button) params = {} - node.xpath(".//input[@type!='radio' and @type!='checkbox' and @type!='submit']").map do |input| + node.xpath(".//input[not(@type) or (@type!='radio' and @type!='checkbox' and @type!='submit')]").map do |input| merge_param!(params, input['name'].to_s, input['value'].to_s) end node.xpath(".//textarea").map do |textarea| diff --git a/lib/capybara/driver/selenium_driver.rb b/lib/capybara/driver/selenium_driver.rb index cc30dd6f8..a76b0f8ba 100644 --- a/lib/capybara/driver/selenium_driver.rb +++ b/lib/capybara/driver/selenium_driver.rb @@ -25,7 +25,7 @@ def value end def set(value) - if tag_name == 'textarea' or (tag_name == 'input' and %w(text password hidden file).include?(type)) + if tag_name == 'textarea' or (tag_name == 'input' and [nil, 'text', 'password', 'hidden', 'file'].include?(type)) node.clear node.send_keys(value.to_s) elsif tag_name == 'input' and type == 'radio' diff --git a/lib/capybara/spec/session/fill_in_spec.rb b/lib/capybara/spec/session/fill_in_spec.rb index b19746468..4477aae91 100644 --- a/lib/capybara/spec/session/fill_in_spec.rb +++ b/lib/capybara/spec/session/fill_in_spec.rb @@ -59,6 +59,12 @@ extract_results(@session)['schmooo'].should == 'Schmooo is the game' end + it "should fill in a field without a type" do + @session.fill_in('Phone', :with => '+1 555 7022') + @session.click_button('awesome') + extract_results(@session)['phone'].should == '+1 555 7022' + end + it "should fill in a password field by name" do @session.fill_in('form[password]', :with => 'supasikrit') @session.click_button('awesome') diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index 06cf50d56..8794f1200 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -46,7 +46,7 @@

- +