Skip to content

Commit

Permalink
Updating SelectOptionLocator to use elements
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 30, 2008
1 parent ac4feb3 commit 0eee6d7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/webrat/core/locators/select_option_locator.rb
Expand Up @@ -13,7 +13,6 @@ def initialize(scope, option_text, id_or_name_or_label)
end

def locate
# TODO - Convert to using elements
if @id_or_name_or_label
field = FieldLocator.new(@scope, @id_or_name_or_label, SelectField).locate!

Expand All @@ -25,21 +24,22 @@ def locate
end
end
else
@scope.send(:forms).detect_mapped do |form|
select_fields = form.send(:fields_by_type, [SelectField])
select_fields.detect_mapped do |select_field|
select_field.send(:options).detect do |o|
if @option_text.is_a?(Regexp)
Webrat::XML.inner_html(o.element) =~ @option_text
else
Webrat::XML.inner_html(o.element) == @option_text.to_s
end
end
option_element = option_elements.detect do |o|
if @option_text.is_a?(Regexp)
Webrat::XML.inner_html(o) =~ @option_text
else
Webrat::XML.inner_html(o) == @option_text.to_s
end
end

SelectOption.load(@scope.session, option_element)
end
end

def option_elements
Webrat::XML.xpath_search(@scope.dom, *SelectOption.xpath_search)
end

def error_message
if @id_or_name_or_label
"The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
Expand Down

0 comments on commit 0eee6d7

Please sign in to comment.