lib/rspec_html/search.rb in rspec-html-0.3.0 vs lib/rspec_html/search.rb in rspec-html-0.3.1

- old
+ new

@@ -115,16 +115,16 @@ attr_reader :element_wrapper def index(val) zero_index_error if val.zero? - self.class.new(@siblings[val - 1], @element.name, element_wrapper) + Element.new(@siblings[val - 1], @element.name) end def range(val) zero_index_error if val.first.zero? - self.class.new(@siblings[(val.first - 1)..(val.last - 1)], :range, element_wrapper) + @siblings[(val.first - 1)..(val.last - 1)].map { |element| Element.new(element, @element.name) } end def zero_index_error raise ArgumentError, 'Index for matched sets starts at 1, not 0.' end @@ -147,10 +147,13 @@ end end def where_xpath(tag, query) conditions = "[#{where_conditions(query)}]" unless query.compact.empty? - @element&.xpath(".//#{tag}#{conditions}") + result = @element&.xpath(".//#{tag}#{conditions}") + return result unless @siblings.is_a?(Nokogiri::XML::NodeSet) && result.empty? + + @siblings.xpath(".//#{tag}#{conditions}") end def where_conditions(query) query.compact.map do |key, value| next if value.nil?