Class: Napybara::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/napybara/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, parent = nil, selector_string = nil, &block) ⇒ Element

Returns a new instance of Element.



9
10
11
12
13
14
15
# File 'lib/napybara/element.rb', line 9

def initialize(node, parent = nil, selector_string = nil, &block)
  @node = node
  @parent = parent
  @selector_string = selector_string

  block.call(self) if block_given?
end

Instance Attribute Details

#nodeObject (readonly) Also known as: get

Returns the value of attribute node.



5
6
7
# File 'lib/napybara/element.rb', line 5

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/napybara/element.rb', line 5

def parent
  @parent
end

#selector_stringObject (readonly)

Returns the value of attribute selector_string.



5
6
7
# File 'lib/napybara/element.rb', line 5

def selector_string
  @selector_string
end

Instance Method Details

#finder(child_element_name, child_element_selector, *optional_args, &block) ⇒ Object



17
18
19
20
21
22
# File 'lib/napybara/element.rb', line 17

def finder(child_element_name, child_element_selector, *optional_args, &block)
  appender = FinderMethodsAppender.new(
    self, child_element_name, child_element_selector, optional_args, block)

  appender.execute
end

#inspectObject



24
25
26
# File 'lib/napybara/element.rb', line 24

def inspect
  %(#<Napybara::Element selector="#{selector}">)
end

#rootObject



28
29
30
# File 'lib/napybara/element.rb', line 28

def root
  parent ? parent.parent : self
end

#selectorObject



32
33
34
35
# File 'lib/napybara/element.rb', line 32

def selector
  parent_selector = parent.try(:selector)
  parent_selector ? "#{parent_selector} #{selector_string}" : selector_string
end