Sha256: 5efc373280144e47af24d7c80a178db7cf1340bad641a96d3adcab5f41678573

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Watir
  class CheckBox < Input
    #
    # Sets checkbox to the given value.
    #
    # @example
    #   checkbox = browser.checkbox(id: 'new_user_interests_cars')
    #   checkbox.set?        #=> false
    #   checkbox.set
    #   checkbox.set?        #=> true
    #   checkbox.set(false)
    #   checkbox.set?        #=> false
    #
    # @param [Boolean] bool
    #

    def set(bool = true)
      set? == bool ? assert_enabled : click
    end
    alias check set

    #
    # Returns true if the element is checked
    # @return [Boolean]
    #

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

    #
    # Unsets checkbox.
    #

    def clear
      set false
    end
    alias uncheck clear
  end # CheckBox

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

    def checkboxes(opts = {})
      CheckBoxCollection.new(self, opts.merge(tag_name: 'input', type: 'checkbox'))
    end
  end # Container

  class CheckBoxCollection < InputCollection
  end # CheckBoxCollection
end # Watir

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-7.3.0 lib/watir/elements/checkbox.rb
watir-7.2.2 lib/watir/elements/checkbox.rb
watir-7.2.1 lib/watir/elements/checkbox.rb
watir-7.2.0 lib/watir/elements/checkbox.rb