Sha256: 6853ee7160d8cc8370f79ade2f32f047d5ed3726f17914c27ff284580ab5b079

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

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 = element_class.new(self, :object, obj)

      element.extend(ClickableElement) unless element.is_a?(ClickableElement)

      element
    end


  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
celerity-0.8.5 lib/celerity/xpath_support.rb
celerity-0.8.4 lib/celerity/xpath_support.rb
celerity-0.8.2 lib/celerity/xpath_support.rb
celerity-0.8.1 lib/celerity/xpath_support.rb
oki-celerity-0.8.2 lib/celerity/xpath_support.rb
oki-celerity-0.8.1 lib/celerity/xpath_support.rb
oki-celerity-0.8.1.dev lib/celerity/xpath_support.rb
celerity-0.8.0 lib/celerity/xpath_support.rb
celerity-0.8.0.beta.4 lib/celerity/xpath_support.rb
celerity-0.8.0.beta.3 lib/celerity/xpath_support.rb
celerity-0.8.0.beta.2 lib/celerity/xpath_support.rb
celerity-0.8.0.beta.1 lib/celerity/xpath_support.rb
celerity-0.7.9 lib/celerity/xpath_support.rb
celerity-0.7.8 lib/celerity/xpath_support.rb
celerity-0.7.7 lib/celerity/xpath_support.rb