Sha256: 7fa6cbd5e500534bebdf6a66398616093186eae85901af30e5d66d4d52206a71

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Watir
  class Radio < Input
    def build
      @selector[:label] = @selector.delete(:text) if @selector.key?(:text)
      super
    end

    #
    # Selects this radio button.
    #

    def set(bool = true)
      click if bool && !set?
    end
    alias select set

    #
    # Is this radio set?
    #
    # @return [Boolean]
    #

    def set?
      element_call { @element.selected? }
    end
    alias selected? set?

    #
    # Returns the text of the associated label.
    # Returns empty string if no label is found.
    #
    # @return [String]
    #

    def text
      l = label
      l.exist? ? l.text : ''
    end
  end # Radio

  module Container
    def radio(opts = {})
      Radio.new(self, opts.merge(tag_name: 'input', type: 'radio'))
    end

    def radios(opts = {})
      RadioCollection.new(self, opts.merge(tag_name: 'input', type: 'radio'))
    end
  end # Container

  class RadioCollection < InputCollection
    private

    def build
      @selector[:label] = @selector.delete(:text) if @selector.key?(:text)
      super
    end

    def element_class
      Radio
    end
  end # RadioCollection
end # Watir

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
watir-7.1.0 lib/watir/elements/radio.rb
watir-7.0.0 lib/watir/elements/radio.rb
watir-7.0.0.beta5 lib/watir/elements/radio.rb
watir-7.0.0.beta4 lib/watir/elements/radio.rb
watir-7.0.0.beta3 lib/watir/elements/radio.rb
watir-7.0.0.beta2 lib/watir/elements/radio.rb