Permalink
Browse files

searching by :class will match now partially like other tools behave …

…(e.g. jQuery)
  • Loading branch information...
1 parent 028d580 commit 2f075d8e409f73e8be27c53b272bc3bba6196f67 @jarmo jarmo committed Jan 28, 2012
Showing with 19 additions and 33 deletions.
  1. +19 −33 watir/lib/watir/locator.rb
View
@@ -54,11 +54,28 @@ 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
@@ -140,25 +157,6 @@ def locate
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
@@ -227,18 +225,6 @@ def each
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

0 comments on commit 2f075d8

Please sign in to comment.