Class: Capybara::Query

### Home Classes Methods

### In Files

- lib/capybara/query.rb

### Parent

Capybara::Queries::BaseQuery

### Methods

- ::new
- #css
- #description
- #exact?
- #label
- #match
- #matches_filters?
- #name
- #resolve_for
- #visible
- #xpath

### 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::Query

@deprecated This class and its methods are not supposed to be used by users of Capybara's public API.

    It may be removed in future versions of Capybara.

### Constants

VALID_KEYS
VALID_MATCH

### Attributes

expression[RW]
find[RW]
locator[RW]
negative[RW]
options[RW]
selector[RW]

### Public Class Methods

new(*args) click to toggle source

    # File lib/capybara/query.rb, line 10
    def initialize(*args)
      @options = if args.last.is_a?(Hash) then args.pop.dup else {} end

      if args[0].is_a?(Symbol)
        @selector = Selector.all[args[0]]
        @locator = args[1]
      else
        @selector = Selector.all.values.find { |s| s.match?(args[0]) }
        @locator = args[0]
      end
      @selector ||= Selector.all[Capybara.default_selector]

      # for compatibility with Capybara 2.0
      if Capybara.exact_options and @selector == Selector.all[:option]
        @options[:exact] = true
      end

      @expression = @selector.call(@locator)
      assert_valid_keys
    end

### Public Instance Methods

css() click to toggle source

    # File lib/capybara/query.rb, line 100
    def css
      @expression
    end

description() click to toggle source

    # File lib/capybara/query.rb, line 34
    def description
      @description = "#{label} #{locator.inspect}"
      @description << " with text #{options[:text].inspect}" if options[:text]
      @description << selector.description(options)
      @description
    end

exact?() click to toggle source

    # File lib/capybara/query.rb, line 75
    def exact?
      if options.has_key?(:exact)
        @options[:exact]
      else
        Capybara.exact
      end
    end

label() click to toggle source

    # File lib/capybara/query.rb, line 32
    def label; selector.label or selector.name; end

match() click to toggle source

    # File lib/capybara/query.rb, line 83
    def match
      if options.has_key?(:match)
        @options[:match]
      else
        Capybara.match
      end
    end

matches_filters?(node) click to toggle source

    # File lib/capybara/query.rb, line 41
    def matches_filters?(node)
      if options[:text]
        regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
        return false if not node.text(visible).match(regexp)
      end
      case visible
        when :visible then return false unless node.visible?
        when :hidden then return false if node.visible?
      end
      selector.custom_filters.each do |name, filter|
        if options.has_key?(name)
          return false unless filter.matches?(node, options[name])
        elsif filter.default?
          return false unless filter.matches?(node, filter.default)
        end
      end
    end

name() click to toggle source

    # File lib/capybara/query.rb, line 31
    def name; selector.name; end

resolve_for(node, exact = nil) click to toggle source

@api private

    # File lib/capybara/query.rb, line 105
    def resolve_for(node, exact = nil)
      node.synchronize do
        children = if selector.format == :css
          node.find_css(self.css)
        else
          node.find_xpath(self.xpath(exact))
        end.map do |child|
          if node.is_a?(Capybara::Node::Base)
            Capybara::Node::Element.new(node.session, child, node, self)
          else
            Capybara::Node::Simple.new(child)
          end
        end
        Capybara::Result.new(children, self)
      end
    end

visible() click to toggle source

    # File lib/capybara/query.rb, line 59
    def visible
      if options.has_key?(:visible)
        case @options[:visible]
          when true then :visible
          when false then :all
          else @options[:visible]
        end
      else
        if Capybara.ignore_hidden_elements
          :visible
        else
          :all
        end
      end
    end

xpath(exact=nil) click to toggle source

    # File lib/capybara/query.rb, line 91
    def xpath(exact=nil)
      exact = self.exact? if exact == nil
      if @expression.respond_to?(:to_xpath) and exact
        @expression.to_xpath(:exact)
      else
        @expression.to_s
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.