From 7ef8fdf7ba0344231c2dae666ecfcb2d1ebedfb1 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Thu, 27 Nov 2008 00:40:18 -0500 Subject: [PATCH] Processing CSS searches as XPath --- lib/webrat/core/xml.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/webrat/core/xml.rb b/lib/webrat/core/xml.rb index b3385e1..465a441 100644 --- a/lib/webrat/core/xml.rb +++ b/lib/webrat/core/xml.rb @@ -25,9 +25,16 @@ module Webrat #:nodoc: 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: if Webrat.configuration.parse_with_nokogiri? - element.css(*searches) + xpath_search(element, css_to_xpath(*searches)) + # element.css(*searches) else searches.map do |search| element.search(search) @@ -35,5 +42,11 @@ module Webrat #:nodoc: end end + def self.css_to_xpath(*selectors) + selectors.map do |rule| + Nokogiri::CSS.xpath_for(rule, :prefix => ".//") + end.flatten.uniq + end + end end \ No newline at end of file