Sha256: 6e7e3a65a9438c6e426f5fbbda4a762f7a177b67c353fd92c8617c003d802b51

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 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, ":xpath and #{xpath.inspect}")
    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) }
    end

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

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

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

      element
    end
  end
end

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
celerity_thingista-0.9.3 lib/celerity/xpath_support.rb
celerity_thingista-0.9.2 lib/celerity/xpath_support.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/celerity-0.9.2/lib/celerity/xpath_support.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/celerity-0.9.2/lib/celerity/xpath_support.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/celerity-0.9.2/lib/celerity/xpath_support.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/celerity-0.9.2/lib/celerity/xpath_support.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/celerity-0.9.2/lib/celerity/xpath_support.rb
celerity-0.9.2 lib/celerity/xpath_support.rb
celerity-0.9.1 lib/celerity/xpath_support.rb
no-click-exception-celerity-0.9.0 lib/celerity/xpath_support.rb
celerity-0.9.0 lib/celerity/xpath_support.rb
celerity-0.8.9 lib/celerity/xpath_support.rb
celerity-0.8.9.pre lib/celerity/xpath_support.rb
celerity-0.8.8 lib/celerity/xpath_support.rb
celerity-0.8.7 lib/celerity/xpath_support.rb
celerity-0.8.6 lib/celerity/xpath_support.rb