class Capybara::Poltergeist::Node

Attributes

id[R]
page_id[R]

Public Class Methods

new(driver, page_id, id) click to toggle source
Calls superclass method
# File lib/capybara/poltergeist/node.rb, line 5
def initialize(driver, page_id, id)
  super(driver, self)

  @page_id = page_id
  @id      = id
end

Public Instance Methods

==(other) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 139
def ==(other)
  command :equals, other.id
end
[](name) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 53
def [](name)
  command :attribute, name
end
all_text() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 45
def all_text
  filter_text command(:all_text)
end
attributes() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 57
def attributes
  command :attributes
end
browser() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 12
def browser
  driver.browser
end
checked?() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 103
def checked?
  self[:checked]
end
click() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 115
def click
  command :click
end
command(name, *args) click to toggle source
# 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?() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 111
def disabled?
  command :disabled?
end
double_click() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 123
def double_click
  command :double_click
end
drag_to(other) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 131
def drag_to(other)
  command :drag, other.id
end
find(method, selector) click to toggle source
# 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) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 41
def find_css(selector)
  find :css, selector
end
find_xpath(selector) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 37
def find_xpath(selector)
  find :xpath, selector
end
hover() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 127
def hover
  command :hover
end
parents() click to toggle source
# 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_click() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 119
def right_click
  command :right_click
end
select_option() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 86
def select_option
  command :select, true
end
selected?() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 107
def selected?
  self[:selected]
end
send_key(*keys)
Alias for: send_keys
send_keys(*keys) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 143
def send_keys(*keys)
  command :send_keys, keys
end
Also aliased as: send_key
set(value) click to toggle source
# 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_name() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 95
def tag_name
  @tag_name ||= command(:tag_name)
end
trigger(event) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 135
def trigger(event)
  command :trigger, event
end
unselect_option() click to toggle source
# 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
value() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 61
def value
  command :value
end
visible?() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 99
def visible?
  command :visible?
end
visible_text() click to toggle source
# File lib/capybara/poltergeist/node.rb, line 49
def visible_text
  filter_text command(:visible_text)
end

Private Instance Methods

filter_text(text) click to toggle source
# File lib/capybara/poltergeist/node.rb, line 150
def filter_text(text)
  Capybara::Helpers.normalize_whitespace(text.to_s)
end