Class: Napybara::Element
- Inherits:
-
Object
- Object
- Napybara::Element
- Defined in:
- lib/napybara/element.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
(also: #get)
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#selector_string ⇒ Object
readonly
Returns the value of attribute selector_string.
Instance Method Summary collapse
- #finder(child_element_name, child_element_selector, record_selector = nil, &block) ⇒ Object
-
#initialize(node, parent = nil, selector_string = nil, &block) ⇒ Element
constructor
A new instance of Element.
- #selector ⇒ Object
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
#node ⇒ Object (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 |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/napybara/element.rb', line 5 def parent @parent end |
#selector_string ⇒ Object (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, record_selector = nil, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/napybara/element.rb', line 17 def finder(child_element_name, child_element_selector, record_selector = nil, &block) self.define_singleton_method(child_element_name) do |record = nil| selector = Selector.new(child_element_selector, record_selector, record) selector_string = selector.to_s self.class.new(self.get.find(selector_string), self, selector_string, &block) end self.define_singleton_method("has_#{child_element_name}?") do |record = nil| selector = Selector.new(child_element_selector, record_selector, record) self.get.has_css?(selector.to_s) end self.define_singleton_method("has_no_#{child_element_name}?") do |record = nil| selector = Selector.new(child_element_selector, record_selector, record) self.get.has_no_css?(selector.to_s) end self.define_singleton_method(child_element_name.to_s.pluralize) do elements = self.get.all(child_element_selector) .map.with_index do |child_element, i| self.class.new(child_element, self, child_element_selector, &block) end ElementArray.new(elements, self, child_element_selector) end end |
#selector ⇒ Object
46 47 48 49 |
# File 'lib/napybara/element.rb', line 46 def selector parent_selector = parent.try(:selector) parent_selector ? "#{parent_selector} #{selector_string}" : selector_string end |