Adding Webrat::XML.xpath_to method

This commit is contained in:
Bryan Helmkamp 2008-11-29 00:49:00 -05:00
parent 6316faae44
commit 857625840f
6 changed files with 14 additions and 20 deletions

View File

@ -15,11 +15,7 @@ module Webrat
end
def path
if Webrat.configuration.parse_with_nokogiri?
@element.path
else
@element.xpath
end
Webrat::XML.xpath_to(@element)
end
protected

View File

@ -27,11 +27,7 @@ module Webrat
end
def path
if Webrat.configuration.parse_with_nokogiri?
@element.path
else
@element.xpath
end
Webrat::XML.xpath_to(@element)
end
def matches_name?(name)

View File

@ -18,11 +18,7 @@ module Webrat
def field_by_element(element, *field_types)
return nil if element.nil?
if Webrat.configuration.parse_with_nokogiri?
expected_path = element.path
else
expected_path = element.xpath
end
expected_path = Webrat::XML.xpath_to(element)
fields_by_type(field_types).detect do |possible_field|
possible_field.path == expected_path

View File

@ -55,11 +55,7 @@ module Webrat
def area_by_element(element)
return nil if element.nil?
if Webrat.configuration.parse_with_nokogiri?
expected_path = element.path
else
expected_path = element.xpath
end
expected_path = Webrat::XML.xpath_to(element)
areas.detect do |possible_area|
possible_area.path == expected_path

View File

@ -38,6 +38,7 @@ module Webrat
@data = {}
@default_headers = {}
@custom_headers = {}
@elements = {}
@context = context
end
@ -110,6 +111,7 @@ module Webrat
save_and_open_page if exception_caught? && Webrat.configuration.open_error_files?
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
@elements = {}
@_scopes = nil
@_page_scope = nil
@current_url = url

View File

@ -62,6 +62,14 @@ module Webrat #:nodoc:
end
end
def self.xpath_to(element)
if Webrat.configuration.parse_with_nokogiri?
element.path
else
element.xpath
end
end
def self.attribute(element, attribute_name)
return element[attribute_name] if element.is_a?(Hash)