lib/watir/locator.rb in watir-3.0.0.rc1 vs lib/watir/locator.rb in watir-3.0.0.rc2

- old
+ new

@@ -52,15 +52,32 @@ def match_with_specifiers?(element) return true if has_excluding_specifiers? @specifiers.all? do |how, what| how == :index || - (how.to_s =~ /^data_.*/ && element.send(how) == what) || - match?(element, how, what) + (how == :class_name && match_class?(element, what)) || + match?(element, how, what) end end + def match_class? element, what + classes = element.class_name.split(/\s+/) + classes.any? {|clazz| what.matches(clazz)} + end + + # return true if the element matches the provided how and what + def match? element, how, what + begin + attribute = element.send(how) + rescue NoMethodError + raise MissingWayOfFindingObjectException, + "#{how} is an unknown way of finding a <#{@tags.join(", ")}> element (#{what})" + end + + what.matches(attribute) + end + def has_excluding_specifiers? @specifiers.keys.any? {|specifier| [:css, :xpath, :ole_object].include? specifier} end def set_specifier(how, what=nil) @@ -138,29 +155,10 @@ count += 1 return element.ole_object if count == @specifiers[:index] end # elements nil end - - def match?(element, how, what) - begin - method = element.method(how) - rescue NameError - raise MissingWayOfFindingObjectException, - "#{how} is an unknown way of finding a <#{@tags.join(", ")}> element (#{what})" - end - case method.arity - when 0 - what.matches method.call - when 1 - method.call(what) - else - raise MissingWayOfFindingObjectException, - "#{how} is an unknown way of finding a <#{@tags.join(", ")}> element (#{what})" - end - end - end class FrameLocator < TaggedElementLocator def each_element(tag) frames = document.frames @@ -224,21 +222,9 @@ yield element end end nil end - - # return true if the element matches the provided how and what - def match? element, how, what - begin - attribute = element.send(how) - rescue NoMethodError - raise MissingWayOfFindingObjectException, - "#{how} is an unknown way of finding an <INPUT> element (#{what})" - end - - what.matches(attribute) - end private def locate_by_name the_name = @specifiers[:name]