Sha256: 6aaee87150f553c9ae8442f9ed9ee7783ee8e7c923ad96441818fa8c24a26727

Contents?: true

Size: 1013 Bytes

Versions: 19

Compression:

Stored size: 1013 Bytes

Contents

module Celerity

  #
  # Module to search by xpath
  #

  module XpathSupport

    #
    # Get the first element found matching the given XPath.
    #
    # @param [String] xpath
    # @return [Celerity::Element] An element subclass (or Element if none is found)
    #

    def element_by_xpath(xpath)
      assert_exists
      obj = @page.getFirstByXPath(xpath)
      element_from_dom_node(obj)
    end

    #
    # Get all the elements matching the given XPath.
    #
    # @param [String] xpath
    # @return [Array<Celerity::Element>] array of elements
    #

    def elements_by_xpath(xpath)
      assert_exists
      objects = @page.getByXPath(xpath)
      # should use an ElementCollection here?
      objects.map { |o| element_from_dom_node(o) }.compact
    end

    #
    # Convert the given HtmlUnit DomNode to a Celerity object
    #

    def element_from_dom_node(obj)
      element_class = Util.htmlunit2celerity(obj.class) || Element
      element_class.new(self, :object, obj)
    end


  end

end

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
drnic-celerity-0.0.6.17 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.14 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.15 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.16 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.17 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.18 lib/celerity/xpath_support.rb
jarib-celerity-0.0.6.19 lib/celerity/xpath_support.rb
jarib-celerity-0.0.7.1 lib/celerity/xpath_support.rb
fletcherm-culerity-0.2.9 vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb
fletcherm-culerity-0.2.8 vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb
fletcherm-culerity-0.2.7 vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb
fletcherm-culerity-0.2.6 vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb
fletcherm-culerity-0.2.5 vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb
celerity-0.7.6 lib/celerity/xpath_support.rb
celerity-0.7.5 lib/celerity/xpath_support.rb
celerity-0.7.4 lib/celerity/xpath_support.rb
celerity-0.7.3 lib/celerity/xpath_support.rb
celerity-0.0.7.2 lib/celerity/xpath_support.rb
celerity-0.0.7 lib/celerity/xpath_support.rb