Use Nokigiri #search instead of /

This commit is contained in:
Bryan Helmkamp 2008-11-07 02:58:32 -05:00
parent e5b0e77332
commit 0cb64f6483
3 changed files with 15 additions and 13 deletions

View File

@ -311,8 +311,8 @@ module Webrat
protected
def default_value
selected_options = @element / ".//option[@selected='selected']"
selected_options = @element / ".//option[position() = 1]" if selected_options.empty?
selected_options = @element.search(".//option[@selected='selected']")
selected_options = @element.search(".//option[position() = 1]") if selected_options.empty?
selected_options.map do |option|
return "" if option.nil?
@ -325,7 +325,7 @@ module Webrat
end
def option_elements
(@element / ".//option")
@element.search(".//option")
end
end

View File

@ -1,3 +1,5 @@
require "webrat/core_extensions/meta_class"
module Webrat
def self.nokogiri_document(stringlike)
@ -14,6 +16,12 @@ module Webrat
end
end
def self.define_dom_method(object, dom)
object.meta_class.send(:define_method, :dom) do
dom
end
end
end

View File

@ -1,7 +1,6 @@
require "nokogiri"
require "webrat/core/form"
require "webrat/core/locators"
require "webrat/core_extensions/meta_class"
module Webrat
class Scope
@ -168,13 +167,8 @@ module Webrat
def page_dom
return @response.dom if @response.respond_to?(:dom)
dom = Webrat.nokogiri_document(@response_body)
@response.meta_class.send(:define_method, :dom) do
dom
end
Webrat.define_dom_method(@response, dom)
return dom
end
@ -191,13 +185,13 @@ module Webrat
end
def areas
(dom / "area").map do |element|
dom.search("area").map do |element|
Area.new(@session, element)
end
end
def links
(dom / "a[@href]").map do |link_element|
dom.search("a[@href]").map do |link_element|
Link.new(@session, link_element)
end
end
@ -205,7 +199,7 @@ module Webrat
def forms
return @forms if @forms
@forms = (dom / "form").map do |form_element|
@forms = dom.search("form").map do |form_element|
Form.new(@session, form_element)
end
end