Extract FieldByIdLocator object
This commit is contained in:
parent
9e030a1b05
commit
04959ae457
|
@ -68,17 +68,9 @@ module Webrat
|
|||
end
|
||||
|
||||
def find_field_with_id(id, *field_types) #:nodoc:
|
||||
field_elements = Webrat::XML.xpath_search(dom, *Field.xpath_search)
|
||||
require "webrat/core/locators/field_by_id_locator"
|
||||
|
||||
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)
|
||||
FieldByIdLocator.new(self, id).locate
|
||||
end
|
||||
|
||||
def find_select_option(option_text, id_or_name_or_label) #:nodoc:
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
class FieldByIdLocator
|
||||
|
||||
def initialize(scope, value)
|
||||
@scope = scope
|
||||
@value = value
|
||||
end
|
||||
|
||||
def locate
|
||||
@scope.field_by_element(field_element)
|
||||
end
|
||||
|
||||
def field_element
|
||||
field_elements.detect do |field_element|
|
||||
if @value.is_a?(Regexp)
|
||||
Webrat::XML.attribute(field_element, "id") =~ @value
|
||||
else
|
||||
Webrat::XML.attribute(field_element, "id") == @value.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def field_elements
|
||||
Webrat::XML.xpath_search(@scope.dom, *Webrat::Field.xpath_search)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue