Sha256: e435aef99221155fcf39a58ba4bf70c09aab599fce493e1cc67f59cff9fc0112

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

require "webrat/core/locators/locator"

module Webrat
  module Locators

    class FieldByIdLocator < Locator # :nodoc:

      def locate
        Field.load(@session, field_element)
      end

      def field_element
        field_elements.detect do |field_element|
          if @value.is_a?(Regexp)
            field_element["id"] =~ @value
          else
            field_element["id"] == @value.to_s
          end
        end
      end

      def field_elements
        @dom.xpath(*Field.xpath_search)
      end

      def error_message
        "Could not find field with id #{@value.inspect}"
      end

    end

    def field_with_id(id, *field_types)
      FieldByIdLocator.new(@session, dom, id, *field_types).locate!
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mkuklis-webrat-0.6.rc1 lib/webrat/core/locators/field_by_id_locator.rb