Processing CSS searches as XPath

This commit is contained in:
Bryan Helmkamp 2008-11-27 00:40:18 -05:00
parent 56dc8147f2
commit 7ef8fdf7ba

View File

@ -25,9 +25,16 @@ module Webrat #:nodoc:
end end
end end
def self.xpath_search(element, *searches)
searches.flatten.map do |search|
element.xpath(search)
end.flatten.compact
end
def self.css_search(element, *searches) #:nodoc: def self.css_search(element, *searches) #:nodoc:
if Webrat.configuration.parse_with_nokogiri? if Webrat.configuration.parse_with_nokogiri?
element.css(*searches) xpath_search(element, css_to_xpath(*searches))
# element.css(*searches)
else else
searches.map do |search| searches.map do |search|
element.search(search) element.search(search)
@ -35,5 +42,11 @@ module Webrat #:nodoc:
end end
end end
def self.css_to_xpath(*selectors)
selectors.map do |rule|
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
end.flatten.uniq
end
end end
end end