diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 8555b8e..10502b3 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -189,7 +189,7 @@ module Webrat if collection_name? super else - checkbox_with_same_name = @form.field(name, CheckboxField) + checkbox_with_same_name = @form.field_named(name, CheckboxField) if checkbox_with_same_name.to_param.blank? super diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index c9cc668..aff5cd6 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -10,15 +10,10 @@ module Webrat @element = element @fields = nil end - - def field(locator, *field_types) - field_with_id(locator, *field_types) || - field_named(locator, *field_types) || - field_labeled(locator, *field_types) || - nil - end def field_by_element(element, *field_types) + return nil if element.nil? + if Webrat.configuration.parse_with_nokogiri? expected_path = element.path else @@ -63,11 +58,6 @@ module Webrat def submit @session.request_page(form_action, form_method, params) end - - def field_with_id(id, *field_types) - possible_fields = fields_by_type(field_types) - possible_fields.detect { |possible_field| possible_field.matches_id?(id) } - end def field_named(name, *field_types) possible_fields = fields_by_type(field_types) diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index ea8361c..7d635e8 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -46,12 +46,26 @@ module Webrat end end - def find_field_with_id(id, *field_types) #:nodoc: + def field_by_element(element, *field_types) forms.detect_mapped do |form| - form.field_with_id(id, *field_types) + form.field_by_element(element, *field_types) end end + def find_field_with_id(id, *field_types) #:nodoc: + field_elements = Webrat::XML.css_search(dom, "button", "input", "textarea", "select") + + field_element = field_elements.detect do |field_element| + if id.is_a?(Regexp) + Webrat::XML.attribute(field_element, "id") =~ id + else + Webrat::XML.attribute(field_element, "id") == id.to_s + end + end + + field_by_element(field_element) + end + def find_select_option(option_text, id_or_name_or_label) #:nodoc: if id_or_name_or_label field = field(id_or_name_or_label, SelectField)