diff --git a/TODO.txt b/TODO.txt index 6cfdd60..09d1dfe 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,4 +1,3 @@ -Switch from Nokogiri::Hpricot to Nokogiri::HTML Add tests for locator strategies Use Webrat::Methods for Merb and Rails integration Get file uploads workign with merb diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 8439f22..b0efb93 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -111,7 +111,7 @@ module Webrat end unless id.blank? - @label_elements += @form.element / "label[@for=#{id}]" + @label_elements += @form.element.search("label[@for='#{id}']") end @label_elements @@ -311,8 +311,9 @@ module Webrat protected def default_value - selected_options = @element / "option[@selected='selected']" - selected_options = @element / "option:first" if selected_options.empty? + selected_options = @element / ".//option[@selected='selected']" + selected_options = @element / ".//option[position() = 1]" if selected_options.empty? + selected_options.map do |option| return "" if option.nil? option["value"] || option.inner_html @@ -324,7 +325,7 @@ module Webrat end def option_elements - (@element / "option") + (@element / ".//option") end end diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index 39ce99b..4ab2182 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -39,7 +39,7 @@ module Webrat def fields return @fields if @fields - @fields = (@element / "button, input, textarea, select").collect do |field_element| + @fields = (@element.search(".//button", ".//input", ".//textarea", ".//select")).collect do |field_element| Field.class_for_element(field_element).new(self, field_element) end end diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index 46c0d44..69bf75d 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -139,7 +139,7 @@ module Webrat alias_method :clicks_button, :click_button def dom # :nodoc: - @dom ||= Nokogiri::Hpricot(scoped_html) + @dom ||= Nokogiri::HTML(scoped_html) end protected @@ -155,7 +155,7 @@ module Webrat def scoped_html @scoped_html ||= begin if @selector - (Nokogiri::Hpricot(@html) / @selector).first.to_html + (Nokogiri::HTML(@html) / @selector).first.to_html else @html end diff --git a/spec/webrat/core/field_spec.rb b/spec/webrat/core/field_spec.rb index 5fb3fea..609ea35 100644 --- a/spec/webrat/core/field_spec.rb +++ b/spec/webrat/core/field_spec.rb @@ -3,12 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") module Webrat describe CheckboxField do it "should say it is checked if it is" do - checkbox = CheckboxField.new(nil, (Nokogiri::Hpricot("")/'input').first) + checkbox = CheckboxField.new(nil, (Nokogiri::HTML("")/'input').first) checkbox.should be_checked end it "should say it is not checked if it is not" do - checkbox = CheckboxField.new(nil, (Nokogiri::Hpricot("")/'input').first) + checkbox = CheckboxField.new(nil, (Nokogiri::HTML("")/'input').first) checkbox.should_not be_checked end end