Sha256: 19f40740e671278ad708bea60eb4d84ce7b1d3115b73e2f762938e272f486cb7

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 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
      click unless 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(*args)
      Radio.new(self, extract_selector(args).merge(tag_name: 'input', type: 'radio'))
    end

    def radios(*args)
      RadioCollection.new(self, extract_selector(args).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

4 entries across 4 versions & 1 rubygems

Version Path
watir-6.19.1 lib/watir/elements/radio.rb
watir-6.19.0 lib/watir/elements/radio.rb
watir-6.18.0 lib/watir/elements/radio.rb
watir-6.17.0 lib/watir/elements/radio.rb