Class: Capybara::Selenium::Node

### Home Classes Methods

### In Files

- lib/capybara/selenium/node.rb

### Parent

Capybara::Driver::Node

### Methods

- #==
- #[]
- #all_text
- #checked?
- #click
- #disabled?
- #double_click
- #drag_to
- #find_css
- #find_xpath
- #hover
- #right_click
- #select_option
- #selected?
- #set
- #tag_name
- #unselect_option
- #value
- #visible?
- #visible_text

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::Selenium::Node

### Public Instance Methods

==(other) click to toggle source

    # File lib/capybara/selenium/node.rb, line 120
    def ==(other)
      native == other.native
    end

[](name) click to toggle source

    # File lib/capybara/selenium/node.rb, line 12
    def [](name)
      native.attribute(name.to_s)
    rescue Selenium::WebDriver::Error::WebDriverError
      nil
    end

all_text() click to toggle source

    # File lib/capybara/selenium/node.rb, line 7
    def all_text
      text = driver.browser.execute_script("return arguments[0].textContent", native)
      Capybara::Helpers.normalize_whitespace(text)
    end

checked?() click to toggle source
Alias for: selected?
click() click to toggle source

    # File lib/capybara/selenium/node.rb, line 72
    def click
      native.click
    end

disabled?() click to toggle source

    # File lib/capybara/selenium/node.rb, line 106
    def disabled?
      !native.enabled?
    end

double_click() click to toggle source

    # File lib/capybara/selenium/node.rb, line 80
    def double_click
      driver.browser.action.double_click(native).perform
    end

drag_to(element) click to toggle source

    # File lib/capybara/selenium/node.rb, line 88
    def drag_to(element)
      driver.browser.action.drag_and_drop(native, element.native).perform
    end

find_css(locator) click to toggle source

    # File lib/capybara/selenium/node.rb, line 116
    def find_css(locator)
      native.find_elements(:css, locator).map { |n| self.class.new(driver, n) }
    end

find_xpath(locator) click to toggle source

    # File lib/capybara/selenium/node.rb, line 112
    def find_xpath(locator)
      native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
    end

hover() click to toggle source

    # File lib/capybara/selenium/node.rb, line 84
    def hover
      driver.browser.action.move_to(native).perform
    end

right_click() click to toggle source

    # File lib/capybara/selenium/node.rb, line 76
    def right_click
      driver.browser.action.context_click(native).perform
    end

select_option() click to toggle source

    # File lib/capybara/selenium/node.rb, line 61
    def select_option
      native.click unless selected?
    end

selected?() click to toggle source

    # File lib/capybara/selenium/node.rb, line 101
    def selected?
      selected = native.selected?
      selected and selected != "false"
    end

Also aliased as: checked?
set(value) click to toggle source

    # File lib/capybara/selenium/node.rb, line 26
    def set(value)
      tag_name = self.tag_name
      type = self[:type]
      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'
        click
      elsif tag_name == 'input' and type == 'checkbox'
        click if value ^ native.attribute('checked').to_s.eql?("true")
      elsif tag_name == 'input' and type == 'file'
        path_names = value.to_s.empty? ? [] : value
        native.send_keys(*path_names)
      elsif tag_name == 'textarea' or tag_name == 'input'
        if self[:readonly]
          warn "Attempt to set readonly element with value: #{value} \n *This will raise an exception in a future version of Capybara"
        elsif value.to_s.empty?
          native.clear
        else
          #script can change a readonly element which user input cannot, so dont execute if readonly
          driver.browser.execute_script "arguments[0].value = ''", native
          native.send_keys(value.to_s)
        end
      elsif native.attribute('isContentEditable')
        #ensure we are focused on the element
        script =         var range = document.createRange();        range.selectNodeContents(arguments[0]);        window.getSelection().addRange(range);
        driver.browser.execute_script script, native
        native.send_keys(value.to_s)
      end
    end

tag_name() click to toggle source

    # File lib/capybara/selenium/node.rb, line 92
    def tag_name
      native.tag_name.downcase
    end

unselect_option() click to toggle source

    # File lib/capybara/selenium/node.rb, line 65
    def unselect_option
      if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
        raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
      end
      native.click if selected?
    end

value() click to toggle source

    # File lib/capybara/selenium/node.rb, line 18
    def value
      if tag_name == "select" and self[:multiple] and not self[:multiple] == "false"
        native.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n[:value] || n.text }
      else
        native[:value]
      end
    end

visible?() click to toggle source

    # File lib/capybara/selenium/node.rb, line 96
    def visible?
      displayed = native.displayed?
      displayed and displayed != "false"
    end

visible_text() click to toggle source

    # File lib/capybara/selenium/node.rb, line 2
    def visible_text
      # Selenium doesn't normalize Unicode whitespace.
      Capybara::Helpers.normalize_whitespace(native.text)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.