Capybara::Driver::RackTest::Node

Public Instance Methods

[](name) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 12
def [](name)
  attr_name = name.to_s
  case
  when 'select' == tag_name && 'value' == attr_name
    if node['multiple'] == 'multiple'
      node.xpath(".//option[@selected='selected']").map { |option| option.content  }
    else
      option = node.xpath(".//option[@selected='selected']").first || node.xpath(".//option").first
      option.content if option
    end
  when 'input' == tag_name && 'checkbox' == type && 'checked' == attr_name
    node[attr_name] == 'checked' ? true : false
  else
    node[attr_name]
  end
end
click() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 82
def click
  if tag_name == 'a'
    method = self["data-method"] || :get
    driver.process(method, self[:href].to_s)
  elsif (tag_name == 'input' or tag_name == 'button') and %(submit image).include?(type)
    Form.new(driver, form).submit(self)
  end
end
path() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 99
def path
  node.path
end
select(option) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 54
def select(option)
  if node['multiple'] != 'multiple'
    node.xpath(".//option[@selected]").each { |node| node.remove_attribute("selected") }
  end

  if option_node = node.xpath(".//option[text()=#{Capybara::XPath.escape(option)}]").first ||
                   node.xpath(".//option[contains(.,#{Capybara::XPath.escape(option)})]").first
    option_node["selected"] = 'selected'
  else
    options = node.xpath(".//option").map { |o| "'#{o.text}'" }.join(', ')
    raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
  end
end
set(value) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 37
def set(value)
  if tag_name == 'input' and type == 'radio'
    driver.html.xpath("//input[@name=#{Capybara::XPath.escape(self[:name])}]").each { |node| node.remove_attribute("checked") }
    node['checked'] = 'checked'
  elsif tag_name == 'input' and type == 'checkbox'
    if value && !node['checked']
      node['checked'] = 'checked'
    elsif !value && node['checked']
      node.remove_attribute('checked')
    end
  elsif tag_name == 'input'
    node['value'] = value.to_s
  elsif tag_name == "textarea"
    node.content = value.to_s
  end
end
tag_name() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 91
def tag_name
  node.node_name
end
text() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 8
def text
  node.text
end
unselect(option) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 68
def unselect(option)
  if node['multiple'] != 'multiple'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
  end

  if option_node = node.xpath(".//option[text()=#{Capybara::XPath.escape(option)}]").first ||
                   node.xpath(".//option[contains(.,#{Capybara::XPath.escape(option)})]").first
    option_node.remove_attribute('selected')
  else
    options = node.xpath(".//option").map { |o| "'#{o.text}'" }.join(', ')
    raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
  end
end
value() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 29
def value
  if tag_name == 'textarea'
    node.content
  else
    super
  end
end
visible?() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 95
def visible?
  node.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none')]").size == 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.