Looking up Fields using Session#elements hash

This commit is contained in:
Bryan Helmkamp 2008-11-29 01:08:58 -05:00
parent 8e864f7e0d
commit e0488cd8e4
4 changed files with 13 additions and 19 deletions

View File

@ -13,16 +13,8 @@ module Webrat
@session = session
@element = element
@fields = nil
end
def field_by_element(element, *field_types)
return nil if element.nil?
expected_path = Webrat::XML.xpath_to(element)
fields_by_type(field_types).detect do |possible_field|
possible_field.path == expected_path
end
fields # preload
end
def find_select_option(option_text)
@ -44,7 +36,9 @@ module Webrat
[SelectField, TextareaField, ButtonField, CheckboxField, PasswordField,
RadioField, FileField, ResetField, TextField, HiddenField].each do |field_class|
@fields += Webrat::XML.xpath_search(@element, *field_class.xpath_search).map do |element|
field_class.new(self, element)
field = field_class.new(self, element)
@session.elements[Webrat::XML.xpath_to(element)] = field
field
end
end

View File

@ -4,11 +4,7 @@ module Webrat
module Locators
def field_by_xpath(xpath)
element = Webrat::XML.xpath_search(dom, xpath).first
forms.detect_mapped do |form|
form.field_by_element(element)
end
field_by_element(Webrat::XML.xpath_at(dom, xpath))
end
def field(*args) # :nodoc:
@ -47,9 +43,8 @@ module Webrat
end
def field_by_element(element, *field_types)
forms.detect_mapped do |form|
form.field_by_element(element, *field_types)
end
return nil if element.nil?
@session.elements[Webrat::XML.xpath_to(element)]
end
def area_by_element(element)

View File

@ -29,6 +29,7 @@ module Webrat
@session = session
instance_eval(&block) if block_given?
forms # preload
areas # preload
end

View File

@ -78,7 +78,11 @@ module Webrat #:nodoc:
else
element.attributes[attribute_name]
end
end
end
def self.xpath_at(*args)
xpath_search(*args).first
end
def self.xpath_search(element, *searches)
searches.flatten.map do |search|