Capybara::RackTest::Node

Public Instance Methods

==(other) click to toggle source
# File lib/capybara/rack_test/node.rb, line 100
def ==(other)
  native == other.native
end
[](name) click to toggle source
# File lib/capybara/rack_test/node.rb, line 6
def [](name)
  string_node[name]
end
checked?() click to toggle source
# File lib/capybara/rack_test/node.rb, line 84
def checked?
  string_node.checked?
end
click() click to toggle source
# File lib/capybara/rack_test/node.rb, line 65
def click
  if tag_name == 'a'
    method = self["data-method"] if driver.options[:respect_data_method]
    method ||= :get
    driver.follow(method, self[:href].to_s)
  elsif (tag_name == 'input' and %(submit image).include?(type)) or
      ((tag_name == 'button') and type.nil? or type == "submit")
    Capybara::RackTest::Form.new(driver, form).submit(self)
  end
end
find(locator) click to toggle source
# File lib/capybara/rack_test/node.rb, line 96
def find(locator)
  native.xpath(locator).map { |n| self.class.new(driver, n) }
end
path() click to toggle source
# File lib/capybara/rack_test/node.rb, line 92
def path
  native.path
end
select_option() click to toggle source
# File lib/capybara/rack_test/node.rb, line 51
def select_option
  if select_node['multiple'] != 'multiple'
    select_node.find(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
  end
  native["selected"] = 'selected'
end
selected?() click to toggle source
# File lib/capybara/rack_test/node.rb, line 88
def selected?
  string_node.selected?
end
set(value) click to toggle source
# File lib/capybara/rack_test/node.rb, line 14
def set(value)
  if (Array === value) && !self[:multiple]
    raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
  end
  if tag_name == 'input' and type == 'radio'
    other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
    driver.dom.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
    native['checked'] = 'checked'
  elsif tag_name == 'input' and type == 'checkbox'
    if value && !native['checked']
      native['checked'] = 'checked'
    elsif !value && native['checked']
      native.remove_attribute('checked')
    end
  elsif tag_name == 'input'
    if (type == 'text' || type == 'password') && self[:maxlength] &&
      !self[:maxlength].empty?
      # Browser behavior for maxlength="0" is inconsistent, so we stick with
      # Firefox, allowing no input
      value = value[0...self[:maxlength].to_i]
    end
    if Array === value #Assert multiple attribute is present
      value.each do |v|
        new_native = native.clone
        new_native.remove_attribute('value')
        native.add_next_sibling(new_native)
        new_native['value'] = v.to_s
      end
      native.remove
    else
      native['value'] = value.to_s
    end
  elsif tag_name == "textarea"
    native.content = value.to_s
  end
end
tag_name() click to toggle source
# File lib/capybara/rack_test/node.rb, line 76
def tag_name
  native.node_name
end
text() click to toggle source
# File lib/capybara/rack_test/node.rb, line 2
def text
  Capybara::Helpers.normalize_whitespace(unnormalized_text)
end
unselect_option() click to toggle source
# File lib/capybara/rack_test/node.rb, line 58
def unselect_option
  if select_node['multiple'] != 'multiple'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
  end
  native.remove_attribute('selected')
end
value() click to toggle source
# File lib/capybara/rack_test/node.rb, line 10
def value
  string_node.value
end
visible?() click to toggle source
# File lib/capybara/rack_test/node.rb, line 80
def visible?
  string_node.visible?
end

Protected Instance Methods

unnormalized_text() click to toggle source
# File lib/capybara/rack_test/node.rb, line 106
def unnormalized_text
  if !visible?
    ''
  elsif native.text?
    native.text
  elsif native.element?
    native.children.map do |child|
      Capybara::RackTest::Node.new(driver, child).unnormalized_text
    end.join
  else
    ''
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.