Use FieldNamedLocator in form

This commit is contained in:
Bryan Helmkamp 2008-11-30 15:51:44 -05:00
parent 522bb3272f
commit 260ef1ae4e
2 changed files with 6 additions and 6 deletions

View File

@ -64,10 +64,6 @@ module Webrat
def id def id
Webrat::XML.attribute(@element, "id") Webrat::XML.attribute(@element, "id")
end end
def matches_name?(name)
Webrat::XML.attribute(@element, "name") == name.to_s
end
def disabled? def disabled?
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false' @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'

View File

@ -2,6 +2,7 @@ require "webrat/core/elements/field"
require "webrat/core_extensions/blank" require "webrat/core_extensions/blank"
require "webrat/core/elements/element" require "webrat/core/elements/element"
require "webrat/core/locators/field_named_locator"
module Webrat module Webrat
class Form < Element #:nodoc: class Form < Element #:nodoc:
@ -28,12 +29,15 @@ module Webrat
end end
def field_named(name, *field_types) def field_named(name, *field_types)
possible_fields = fields_by_type(field_types) Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
possible_fields.detect { |possible_field| possible_field.matches_name?(name) }
end end
protected protected
def dom
Webrat::XML.xpath_at(@session.dom, path)
end
def fields_by_type(field_types) def fields_by_type(field_types)
if field_types.any? if field_types.any?
fields.select { |f| field_types.include?(f.class) } fields.select { |f| field_types.include?(f.class) }