Class: Capybara::Node::Simple

### Home Classes Methods

### In Files

- lib/capybara/node/simple.rb

### Parent

Object

### Methods

- ::new
- #[]
- #allow_reload!
- #checked?
- #disabled?
- #find_css
- #find_xpath
- #inspect
- #path
- #selected?
- #synchronize
- #tag_name
- #text
- #title
- #value
- #visible?

### Included Modules

- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::DocumentMatchers

### 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::Node::Simple

A {Capybara::Node::Simple} is a simpler version of {Capybara::Node::Base} which includes only {Capybara::Node::Finders} and {Capybara::Node::Matchers} and does not include {Capybara::Node::Actions}. This type of node is returned when using {Capybara.string}.

It is useful in that it does not require a session, an application or a driver, but can still use Capybara's finders and matchers on any string that contains HTML.

### Attributes

native[R]

### Public Class Methods

new(native) click to toggle source

    # File lib/capybara/node/simple.rb, line 21
    def initialize(native)
      native = Capybara::HTML(native) if native.is_a?(String)
      @native = native
    end

### Public Instance Methods

[](name) click to toggle source

Retrieve the given attribute

    element[:title] # => HTML title attribute

@param [Symbol] name The attribute name to retrieve @return [String] The value of the attribute

    # File lib/capybara/node/simple.rb, line 43
    def [](name)
      attr_name = name.to_s
      if attr_name == 'value'
        value
      elsif 'input' == tag_name and 'checkbox' == native[:type] and 'checked' == attr_name
        native['checked'] == 'checked'
      else
        native[attr_name]
      end
    end

allow_reload!() click to toggle source

    # File lib/capybara/node/simple.rb, line 144
    def allow_reload!
      # no op
    end

checked?() click to toggle source

Whether or not the element is checked.

@return [Boolean] Whether the element is checked

    # File lib/capybara/node/simple.rb, line 117
    def checked?
      native[:checked]
    end

disabled?() click to toggle source

Whether or not the element is disabled.

@return [Boolean] Whether the element is disabled

    # File lib/capybara/node/simple.rb, line 126
    def disabled?
      native[:disabled]
    end

find_css(css) click to toggle source

@api private

    # File lib/capybara/node/simple.rb, line 157
    def find_css(css)
      native.css(css)
    end

find_xpath(xpath) click to toggle source

@api private

    # File lib/capybara/node/simple.rb, line 162
    def find_xpath(xpath)
      native.xpath(xpath)
    end

inspect() click to toggle source

    # File lib/capybara/node/simple.rb, line 152
    def inspect
      %(#<Capybara::Node::Simple tag="#{tag_name}" path="#{path}">)
    end

path() click to toggle source

An XPath expression describing where on the page the element can be found

@return [String] An XPath expression

    # File lib/capybara/node/simple.rb, line 68
    def path
      native.path
    end

selected?() click to toggle source

Whether or not the element is selected.

@return [Boolean] Whether the element is selected

    # File lib/capybara/node/simple.rb, line 136
    def selected?
      native[:selected]
    end

synchronize(seconds=nil) click to toggle source

    # File lib/capybara/node/simple.rb, line 140
    def synchronize(seconds=nil)
      yield # simple nodes don't need to wait
    end

tag_name() click to toggle source

@return [String] The tag name of the element

    # File lib/capybara/node/simple.rb, line 58
    def tag_name
      native.node_name
    end

text(type=nil) click to toggle source

@return [String] The text of the element

    # File lib/capybara/node/simple.rb, line 30
    def text(type=nil)
      native.text
    end

title() click to toggle source

    # File lib/capybara/node/simple.rb, line 148
    def title
      native.xpath("//title").first.text
    end

value() click to toggle source

@return [String] The value of the form element

    # File lib/capybara/node/simple.rb, line 76
    def value
      if tag_name == 'textarea'
        native.content
      elsif tag_name == 'select'
        if native['multiple'] == 'multiple'
          native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content  }
        else
          option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
          option[:value] || option.content if option
        end
      elsif tag_name == 'input' && %(radio checkbox).include?(native[:type])
        native[:value] || 'on'
      else
        native[:value]
      end
    end

visible?(check_ancestors = true) click to toggle source

Whether or not the element is visible. Does not support CSS, so the result may be inaccurate.

@param [Boolean] check_ancestors Whether to inherit visibility from ancestors @return [Boolean] Whether the element is visible

    # File lib/capybara/node/simple.rb, line 101
    def visible?(check_ancestors = true)
      if check_ancestors
        #check size because oldest supported nokogiri doesnt support xpath boolean() function
        native.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head']").size() == 0
      else
        #no need for an xpath if only checking the current element
        !(native.has_attribute?('hidden') || (native[:style] =~ /display:\s?none/) || %(script head).include?(tag_name))
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.