diff --git a/lib/webrat/core/elements/element.rb b/lib/webrat/core/elements/element.rb index c4ccb87..b13cb00 100644 --- a/lib/webrat/core/elements/element.rb +++ b/lib/webrat/core/elements/element.rb @@ -13,6 +13,8 @@ module Webrat session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element) end + attr_reader :element + def initialize(session, element) @session = session @element = element diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index cb688a5..551898d 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -68,11 +68,6 @@ module Webrat def matches_name?(name) Webrat::XML.attribute(@element, "name") == name.to_s end - - def matches_label?(label_text) - return false if labels.empty? - labels.any? { |label| label.matches_text?(label_text) } - end def disabled? @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false' diff --git a/lib/webrat/core/elements/form.rb b/lib/webrat/core/elements/form.rb index 176da64..c923498 100644 --- a/lib/webrat/core/elements/form.rb +++ b/lib/webrat/core/elements/form.rb @@ -14,12 +14,9 @@ module Webrat def find_select_option(option_text) select_fields = fields_by_type([SelectField]) - select_fields.each do |select_field| - result = select_field.find_option(option_text) - return result if result + select_fields.detect_mapped do |select_field| + select_field.find_option(option_text) end - - nil end def fields diff --git a/lib/webrat/core/elements/link.rb b/lib/webrat/core/elements/link.rb index da2798a..3828708 100644 --- a/lib/webrat/core/elements/link.rb +++ b/lib/webrat/core/elements/link.rb @@ -32,18 +32,10 @@ module Webrat else matcher = /#{Regexp.escape(link_text.to_s)}/i end - + replace_nbsp(text) =~ matcher || replace_nbsp_ref(inner_html) =~ matcher || title =~ matcher end - def matches_id?(id_or_regexp) - if id_or_regexp.is_a?(Regexp) - (id =~ id_or_regexp) ? true : false - else - (id == id_or_regexp) ? true : false - end - end - def inner_html Webrat::XML.inner_html(@element) end diff --git a/lib/webrat/core/elements/select_option.rb b/lib/webrat/core/elements/select_option.rb index 2d11f6c..ce5a16d 100644 --- a/lib/webrat/core/elements/select_option.rb +++ b/lib/webrat/core/elements/select_option.rb @@ -7,14 +7,6 @@ module Webrat ".//option" end - def matches_text?(text) - if text.is_a?(Regexp) - Webrat::XML.inner_html(@element) =~ text - else - Webrat::XML.inner_html(@element) == text.to_s - end - end - def choose select.raise_error_if_disabled select.set(value) diff --git a/lib/webrat/core/locators/select_option_locator.rb b/lib/webrat/core/locators/select_option_locator.rb index f74ab12..1907395 100644 --- a/lib/webrat/core/locators/select_option_locator.rb +++ b/lib/webrat/core/locators/select_option_locator.rb @@ -15,11 +15,27 @@ module Webrat def locate # TODO - Convert to using elements if @id_or_name_or_label - field = @scope.field(@id_or_name_or_label, SelectField) - field.find_option(@option_text) + field = FieldLocator.new(@scope, @id_or_name_or_label, SelectField).locate! + + 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 else @scope.send(:forms).detect_mapped do |form| - form.find_select_option(@option_text) + 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 + end end end end diff --git a/spec/webrat/core/link_spec.rb b/spec/webrat/core/link_spec.rb index a06f099..2f96f7b 100755 --- a/spec/webrat/core/link_spec.rb +++ b/spec/webrat/core/link_spec.rb @@ -78,23 +78,5 @@ describe Webrat::Link do link.should_receive(:inner_html).and_return('') link.matches_text?('logo.png').should == 10 end - - it "should matches_id? on exact matching id" do - link = Webrat::Link.new(webrat_session, nil) - link.should_receive(:id).and_return("some_id") - link.matches_id?("some_id").should == true - end - - it "should not matches_id? on incorrect id" do - link = Webrat::Link.new(webrat_session, nil) - link.should_receive(:id).and_return("other_id") - link.matches_id?("some_id").should == false - end - - it "should matches_id? on matching id by regexp" do - link = Webrat::Link.new(webrat_session, nil) - link.should_receive(:id).and_return("some_id") - link.matches_id?(/some/).should == true - end end