Module: Celerity::XpathSupport

Defined in:
lib/celerity/xpath_support.rb

Overview

Module to search by xpath

Method Summary

Method Details

- (Celerity::Element) element_by_xpath(xpath)

Get the first element found matching the given XPath.

Parameters:

  • (String) xpath

Returns:



16
17
18
19
20
# File 'lib/celerity/xpath_support.rb', line 16

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

- (Object) element_from_dom_node(obj)

Convert the given HtmlUnit DomNode to a Celerity object



40
41
42
43
# File 'lib/celerity/xpath_support.rb', line 40

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

- (Array<Celerity::Element>) elements_by_xpath(xpath)

Get all the elements matching the given XPath.

Parameters:

  • (String) xpath

Returns:



29
30
31
32
33
34
# File 'lib/celerity/xpath_support.rb', line 29

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