From 0eee6d75e488d4572ed7fd45820063393e9580f9 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 30 Nov 2008 15:15:50 -0500 Subject: [PATCH] Updating SelectOptionLocator to use elements --- .../core/locators/select_option_locator.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/webrat/core/locators/select_option_locator.rb b/lib/webrat/core/locators/select_option_locator.rb index 1907395..e0bc6f4 100644 --- a/lib/webrat/core/locators/select_option_locator.rb +++ b/lib/webrat/core/locators/select_option_locator.rb @@ -13,7 +13,6 @@ module Webrat 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! @@ -25,21 +24,22 @@ module Webrat 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"