Class: Locator::Dom::Htmlunit::Element
- Defined in:
- lib/locator/dom/htmlunit/element.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #ancestor_of?(other) ⇒ Boolean
- #ancestors ⇒ Object
- #attribute(name) ⇒ Object
- #content ⇒ Object
- #css_path ⇒ Object
- #element_by_id(id) ⇒ Object
- #element_by_xpath(xpath) ⇒ Object
- #elements_by_css(*rules) ⇒ Object
- #elements_by_xpath(*xpaths) ⇒ Object
-
#initialize(element) ⇒ Element
constructor
A new instance of Element.
- #name ⇒ Object
-
#to_s ⇒ Object
def inner_html element.inner_html end.
- #xpath ⇒ Object
Constructor Details
#initialize(element) ⇒ Element
Returns a new instance of Element.
7 8 9 10 |
# File 'lib/locator/dom/htmlunit/element.rb', line 7 def initialize(element) @element = element || raise('nil passed as an element') @matches = [] end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
5 6 7 |
# File 'lib/locator/dom/htmlunit/element.rb', line 5 def element @element end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
5 6 7 |
# File 'lib/locator/dom/htmlunit/element.rb', line 5 def matches @matches end |
Instance Method Details
#<=>(other) ⇒ Object
12 13 14 |
# File 'lib/locator/dom/htmlunit/element.rb', line 12 def <=>(other) to_s.length <=> other.to_s.length end |
#ancestor_of?(other) ⇒ Boolean
74 75 76 |
# File 'lib/locator/dom/htmlunit/element.rb', line 74 def ancestor_of?(other) other.element.ancestors.include?(element) end |
#ancestors ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/locator/dom/htmlunit/element.rb', line 65 def ancestors ancestors, node = [], element.getParentNode until node.getNodeName == '#document' ancestors.unshift(Element.new(node)) node = node.getParentNode end ancestors end |
#attribute(name) ⇒ Object
41 42 43 |
# File 'lib/locator/dom/htmlunit/element.rb', line 41 def attribute(name) element.getAttribute(name) end |
#content ⇒ Object
28 29 30 31 |
# File 'lib/locator/dom/htmlunit/element.rb', line 28 def content # TODO HtmlUnit has asText and getTextContent element.getTextContent # Celerity normalizes this end |
#css_path ⇒ Object
24 25 26 |
# File 'lib/locator/dom/htmlunit/element.rb', line 24 def css_path raise 'not implemented' end |
#element_by_id(id) ⇒ Object
45 46 47 |
# File 'lib/locator/dom/htmlunit/element.rb', line 45 def element_by_id(id) element_by_xpath("//*[@id='#{id}']") end |
#element_by_xpath(xpath) ⇒ Object
49 50 51 52 53 |
# File 'lib/locator/dom/htmlunit/element.rb', line 49 def element_by_xpath(xpath) if element = self.element.getFirstByXPath(xpath) Element.new(element) end end |
#elements_by_css(*rules) ⇒ Object
61 62 63 |
# File 'lib/locator/dom/htmlunit/element.rb', line 61 def elements_by_css(*rules) elements_by_xpath(*::Nokogiri::CSS.xpath_for(*rules)) end |
#elements_by_xpath(*xpaths) ⇒ Object
55 56 57 58 59 |
# File 'lib/locator/dom/htmlunit/element.rb', line 55 def elements_by_xpath(*xpaths) xpaths.map do |xpath| element.getByXPath(xpath).toArray.map { |e| Element.new(e) } end.flatten end |
#name ⇒ Object
16 17 18 |
# File 'lib/locator/dom/htmlunit/element.rb', line 16 def name element.getNodeName end |
#to_s ⇒ Object
def inner_html
element.inner_html
end
37 38 39 |
# File 'lib/locator/dom/htmlunit/element.rb', line 37 def to_s element.asXml end |
#xpath ⇒ Object
20 21 22 |
# File 'lib/locator/dom/htmlunit/element.rb', line 20 def xpath element.getCanonicalXPath end |