Class: Capybara::Poltergeist::Node

Inherits:
Driver::Node
  • Object
show all
Defined in:
lib/capybara/poltergeist/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, page_id, id) ⇒ Node

Returns a new instance of Node.



5
6
7
8
9
10
# File 'lib/capybara/poltergeist/node.rb', line 5

def initialize(driver, page_id, id)
  super(driver, self)

  @page_id = page_id
  @id      = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/capybara/poltergeist/node.rb', line 3

def id
  @id
end

#page_idObject (readonly)

Returns the value of attribute page_id.



3
4
5
# File 'lib/capybara/poltergeist/node.rb', line 3

def page_id
  @page_id
end

Instance Method Details

#==(other) ⇒ Object



139
140
141
# File 'lib/capybara/poltergeist/node.rb', line 139

def ==(other)
  command :equals, other.id
end

#[](name) ⇒ Object



53
54
55
# File 'lib/capybara/poltergeist/node.rb', line 53

def [](name)
  command :attribute, name
end

#all_textObject



45
46
47
# File 'lib/capybara/poltergeist/node.rb', line 45

def all_text
  filter_text command(:all_text)
end

#attributesObject



57
58
59
# File 'lib/capybara/poltergeist/node.rb', line 57

def attributes
  command :attributes
end

#browserObject



12
13
14
# File 'lib/capybara/poltergeist/node.rb', line 12

def browser
  driver.browser
end

#checked?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/capybara/poltergeist/node.rb', line 103

def checked?
  self[:checked]
end

#clickObject



115
116
117
# File 'lib/capybara/poltergeist/node.rb', line 115

def click
  command :click
end

#command(name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capybara/poltergeist/node.rb', line 16

def command(name, *args)
  browser.send(name, page_id, id, *args)
rescue BrowserError => error
  case error.name
  when 'Poltergeist.ObsoleteNode'
    raise ObsoleteNode.new(self, error.response)
  when 'Poltergeist.MouseEventFailed'
    raise MouseEventFailed.new(self, error.response)
  else
    raise
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/capybara/poltergeist/node.rb', line 111

def disabled?
  command :disabled?
end

#double_clickObject



123
124
125
# File 'lib/capybara/poltergeist/node.rb', line 123

def double_click
  command :double_click
end

#drag_to(other) ⇒ Object



131
132
133
# File 'lib/capybara/poltergeist/node.rb', line 131

def drag_to(other)
  command :drag, other.id
end

#find(method, selector) ⇒ Object



33
34
35
# File 'lib/capybara/poltergeist/node.rb', line 33

def find(method, selector)
  command(:find_within, method, selector).map { |id| self.class.new(driver, page_id, id) }
end

#find_css(selector) ⇒ Object



41
42
43
# File 'lib/capybara/poltergeist/node.rb', line 41

def find_css(selector)
  find :css, selector
end

#find_xpath(selector) ⇒ Object



37
38
39
# File 'lib/capybara/poltergeist/node.rb', line 37

def find_xpath(selector)
  find :xpath, selector
end

#hoverObject



127
128
129
# File 'lib/capybara/poltergeist/node.rb', line 127

def hover
  command :hover
end

#parentsObject



29
30
31
# File 'lib/capybara/poltergeist/node.rb', line 29

def parents
  command(:parents).map { |parent_id| self.class.new(driver, page_id, parent_id) }
end

#right_clickObject



119
120
121
# File 'lib/capybara/poltergeist/node.rb', line 119

def right_click
  command :right_click
end

#select_optionObject



86
87
88
# File 'lib/capybara/poltergeist/node.rb', line 86

def select_option
  command :select, true
end

#selected?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/capybara/poltergeist/node.rb', line 107

def selected?
  self[:selected]
end

#send_keys(*keys) ⇒ Object Also known as: send_key



143
144
145
# File 'lib/capybara/poltergeist/node.rb', line 143

def send_keys(*keys)
  command :send_keys, keys
end

#set(value) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/capybara/poltergeist/node.rb', line 65

def set(value)
  if tag_name == 'input'
    case self[:type]
    when 'radio'
      click
    when 'checkbox'
      click if value != checked?
    when 'file'
      files = value.respond_to?(:to_ary) ? value.to_ary.map(&:to_s) : value.to_s
      command :select_file, files
    else
      command :set, value.to_s
    end
  elsif tag_name == 'textarea'
    command :set, value.to_s
  elsif self[:contenteditable] == 'true'
    command :delete_text
    send_keys(value.to_s)
  end
end

#tag_nameObject



95
96
97
# File 'lib/capybara/poltergeist/node.rb', line 95

def tag_name
  @tag_name ||= command(:tag_name)
end

#trigger(event) ⇒ Object



135
136
137
# File 'lib/capybara/poltergeist/node.rb', line 135

def trigger(event)
  command :trigger, event
end

#unselect_optionObject



90
91
92
93
# File 'lib/capybara/poltergeist/node.rb', line 90

def unselect_option
  command(:select, false) or
  raise(Capybara::UnselectNotAllowed, "Cannot unselect option from single select box.")
end

#valueObject



61
62
63
# File 'lib/capybara/poltergeist/node.rb', line 61

def value
  command :value
end

#visible?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/capybara/poltergeist/node.rb', line 99

def visible?
  command :visible?
end

#visible_textObject



49
50
51
# File 'lib/capybara/poltergeist/node.rb', line 49

def visible_text
  filter_text command(:visible_text)
end