From a205b6fa4404e74e7585f99fbdc44201128c4974 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 2 Dec 2008 00:16:15 -0500 Subject: [PATCH] Converting some CSS selectors to XPath --- lib/webrat/core/elements/field.rb | 6 +++--- lib/webrat/core/elements/link.rb | 4 ---- lib/webrat/core/locators/link_locator.rb | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index 12aa87c..8f16ba3 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -138,7 +138,7 @@ module Webrat end unless id.blank? - @label_elements += Webrat::XML.css_search(form.element, "label[@for='#{id}']") + @label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']") end @label_elements @@ -373,8 +373,8 @@ module Webrat protected def default_value - selected_options = Webrat::XML.css_search(@element, "option[@selected='selected']") - selected_options = Webrat::XML.css_search(@element, "option:first") if selected_options.empty? + selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']") + selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty? selected_options.map do |option| return "" if option.nil? diff --git a/lib/webrat/core/elements/link.rb b/lib/webrat/core/elements/link.rb index defa104..3204db5 100644 --- a/lib/webrat/core/elements/link.rb +++ b/lib/webrat/core/elements/link.rb @@ -9,10 +9,6 @@ module Webrat ".//a[@href]" end - def self.css_search - "a[@href]" - end - def click(options = {}) method = options[:method] || http_method return if href =~ /^#/ && method == :get diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb index e1908cf..4523170 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -41,7 +41,7 @@ module Webrat end def link_elements - Webrat::XML.css_search(@dom, *Link.css_search) + Webrat::XML.xpath_search(@dom, *Link.xpath_search) end def replace_nbsp(str)