Module: Celerity::XpathSupport

Included in:
Browser, Frame
Defined in:
lib/celerity/xpath_support.rb

Overview

Module to search by xpath

Instance Method Summary collapse

Instance Method Details

#element_by_xpath(xpath) ⇒ Celerity::Element

Get the first element found matching the given XPath.

Parameters:

  • xpath (String)

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

#element_from_dom_node(obj, identifier_string = nil) ⇒ Object

Convert the given HtmlUnit DomNode to a Celerity object



40
41
42
43
44
45
46
47
48
# File 'lib/celerity/xpath_support.rb', line 40

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

#elements_by_xpath(xpath) ⇒ Array<Celerity::Element>

Get all the elements matching the given XPath.

Parameters:

  • xpath (String)

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) }
end