Sha256: b894d03acbb17dffff0981d0c5e9b416285a03176abb2c1df3b1253774f07b85

Contents?: true

Size: 1.57 KB

Versions: 17

Compression:

Stored size: 1.57 KB

Contents

require "webrat/core_extensions/detect_mapped"
require "webrat/core/locators/locator"

module Webrat
  module Locators

    class SelectOptionLocator < Locator # :nodoc:

      def initialize(session, dom, option_text, id_or_name_or_label)
        @session = session
        @dom = dom
        @option_text = option_text
        @id_or_name_or_label = id_or_name_or_label
      end

      def locate
        if @id_or_name_or_label
          field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!

          field.options.detect do |o|
            if @option_text.is_a?(Regexp)
              o.element.inner_text =~ @option_text
            else
              o.inner_text == @option_text.to_s
            end
          end
        else
          option_element = option_elements.detect do |o|
            if @option_text.is_a?(Regexp)
              o.inner_text =~ @option_text
            else
              o.inner_text == @option_text.to_s
            end
          end

          SelectOption.load(@session, option_element)
        end
      end

      def option_elements
        @dom.xpath(*SelectOption.xpath_search)
      end

      def error_message
        if @id_or_name_or_label
          "The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
        else
          "Could not find option #{@option_text.inspect}"
        end
      end

    end

    def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
      SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
    end

  end
end

Version data entries

17 entries across 17 versions & 9 rubygems

Version Path
revo-webrat-0.7.0.1 lib/webrat/core/locators/select_option_locator.rb
webrat-0.7.1 lib/webrat/core/locators/select_option_locator.rb
davidtrogers-webrat-0.7.0 lib/webrat/core/locators/select_option_locator.rb
revo-webrat-0.7.0 lib/webrat/core/locators/select_option_locator.rb
revo-webrat-0.7.1.pre lib/webrat/core/locators/select_option_locator.rb
webrat-0.7.0 lib/webrat/core/locators/select_option_locator.rb
honkster-webrat-0.6.0.10 lib/webrat/core/locators/select_option_locator.rb
honkster-webrat-0.6.0.9 lib/webrat/core/locators/select_option_locator.rb
darkofabijan-webrat-0.6.1 lib/webrat/core/locators/select_option_locator.rb
kbaum-webrat-0.5.1 lib/webrat/core/locators/select_option_locator.rb
kbaum-webrat-0.6.1.pre lib/webrat/core/locators/select_option_locator.rb
cynergy-webrat-0.6.0 lib/webrat/core/locators/select_option_locator.rb
webrat-0.6.0 lib/webrat/core/locators/select_option_locator.rb
radar-webrat-0.5.1.1 lib/webrat/core/locators/select_option_locator.rb
radar-webrat-0.5.1 lib/webrat/core/locators/select_option_locator.rb
mkuklis-webrat-0.5.1 lib/webrat/core/locators/select_option_locator.rb
honkster-webrat-0.6.0 lib/webrat/core/locators/select_option_locator.rb