Module: Celerity::XpathSupport
Overview
Module to search by xpath
Instance Method Summary collapse
-
#element_by_xpath(xpath) ⇒ Celerity::Element
Get the first element found matching the given XPath.
-
#element_from_dom_node(obj) ⇒ Object
Convert the given HtmlUnit DomNode to a Celerity object.
-
#elements_by_xpath(xpath) ⇒ Array<Celerity::Element>
Get all the elements matching the given XPath.
Instance Method Details
#element_by_xpath(xpath) ⇒ Celerity::Element
Get the first element found matching the given XPath.
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 |
#element_from_dom_node(obj) ⇒ Object
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 |
#elements_by_xpath(xpath) ⇒ Array<Celerity::Element>
Get all the elements matching the given XPath.
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 |