Class: Obxcura::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/obxcura/node.rb

Overview

A live handle to a DOM node inside a Frame. Backed by a CDP remote object, so reads run as function calls bound to that object and reflect the current DOM. Returned by Frame::DOM#at_css / #css.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame, object_id) ⇒ Node

Returns a new instance of Node.

Parameters:

  • frame (Obxcura::Frame)

    the frame the node lives in.

  • object_id (String)

    the CDP objectId of the node.



13
14
15
16
# File 'lib/obxcura/node.rb', line 13

def initialize(frame, object_id)
  @frame = frame
  @object_id = object_id
end

Instance Attribute Details

#object_idString (readonly)

Returns the CDP remote objectId backing this node.

Returns:

  • (String)

    the CDP remote objectId backing this node.



9
10
11
# File 'lib/obxcura/node.rb', line 9

def object_id
  @object_id
end

Instance Method Details

#[](name) ⇒ String?

Read an attribute value.

Parameters:

  • name (String)

    the attribute name.

Returns:

  • (String, nil)

    the attribute value, or nil if absent.



27
28
29
# File 'lib/obxcura/node.rb', line 27

def [](name)
  @frame.call_on(@object_id, "function(name) { return this.getAttribute(name); }", [ name ])
end

#outer_htmlString

Returns the node's serialized outer HTML.

Returns:

  • (String)

    the node's serialized outer HTML.



32
33
34
# File 'lib/obxcura/node.rb', line 32

def outer_html
  @frame.call_on(@object_id, "function() { return this.outerHTML; }")
end

#textString

Returns the visible text of the node and its descendants.

Returns:

  • (String)

    the visible text of the node and its descendants.



19
20
21
# File 'lib/obxcura/node.rb', line 19

def text
  @frame.call_on(@object_id, "function() { return this.textContent; }")
end