Capybara::Driver::Selenium::Node

Public Instance Methods

[](name) click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 9
def [](name)
  if name == :value
    node.value
  else
    node.attribute(name.to_s)
  end
rescue Selenium::WebDriver::Error::WebDriverError
  nil
end
click() click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 60
def click
  node.click
end
drag_to(element) click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 64
def drag_to(element)
  node.drag_and_drop_on(element.node)
end
select(option) click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 38
def select(option)
  option_node = node.find_element(:xpath, ".//option[normalize-space(text())=#{Capybara::XPath.escape(option)}]") || node.find_element(:xpath, ".//option[contains(.,#{Capybara::XPath.escape(option)})]")
  option_node.select
rescue 
  options = node.find_elements(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
  raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end
set(value) click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 27
def set(value)
  if tag_name == 'input' and type == 'radio'
    node.click
  elsif tag_name == 'input' and type == 'checkbox'
    node.click if node.attribute('checked') != value
  elsif tag_name == 'textarea' or tag_name == 'input'
    node.clear
    node.send_keys(value.to_s)
  end
end
tag_name() click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 68
def tag_name
  node.tag_name
end
text() click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 5
def text
  node.text
end
unselect(option) click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 46
def unselect(option)
  if node['multiple'] != 'multiple'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
  end

  begin
    option_node = node.find_element(:xpath, ".//option[normalize-space(text())=#{Capybara::XPath.escape(option)}]") || node.find_element(:xpath, ".//option[contains(.,#{Capybara::XPath.escape(option)})]")
    option_node.clear
  rescue
    options = node.find_elements(: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/selenium_driver.rb, line 19
def value
  if tag_name == "select" and self[:multiple]
    node.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n.text }
  else
    super
  end
end
visible?() click to toggle source
# File lib/capybara/driver/selenium_driver.rb, line 72
def visible?
  node.displayed? and node.displayed? != "false"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.