Looking up Fields using Session#elements hash
This commit is contained in:
parent
8e864f7e0d
commit
e0488cd8e4
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,6 +29,7 @@ module Webrat
|
|||
@session = session
|
||||
instance_eval(&block) if block_given?
|
||||
|
||||
forms # preload
|
||||
areas # preload
|
||||
end
|
||||
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in New Issue