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


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

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

#[](name) ⇒ Object


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

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

#all_textObject


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

def all_text
  filter_text command(:all_text)
end

#browserObject


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

def browser
  driver.browser
end

#checked?Boolean

Returns:

  • (Boolean)

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

def checked?
  self[:checked]
end

#clickObject


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

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)

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

def disabled?
  command :disabled?
end

#double_clickObject


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

def double_click
  command :double_click
end

#drag_to(other) ⇒ Object


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

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

#find(method, selector) ⇒ Object


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

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

#find_css(selector) ⇒ Object


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

def find_css(selector)
  find :css, selector
end

#find_xpath(selector) ⇒ Object


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

def find_xpath(selector)
  find :xpath, selector
end

#hoverObject


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

def hover
  command :hover
end

#select_optionObject


78
79
80
# File 'lib/capybara/poltergeist/node.rb', line 78

def select_option
  command :select, true
end

#selected?Boolean

Returns:

  • (Boolean)

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

def selected?
  self[:selected]
end

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


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

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

#set(value) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/capybara/poltergeist/node.rb', line 57

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


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

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

#trigger(event) ⇒ Object


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

def trigger(event)
  command :trigger, event
end

#unselect_optionObject


82
83
84
85
# File 'lib/capybara/poltergeist/node.rb', line 82

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

#valueObject


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

def value
  command :value
end

#visible?Boolean

Returns:

  • (Boolean)

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

def visible?
  command :visible?
end

#visible_textObject


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

def visible_text
  filter_text command(:visible_text)
end