Sha256: 2a27af9c2e28b220060acdb87b827ad90305f52caf68f7e0cfff5530d3e9dc72

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

module Watir
  class CheckBox < Input

    #
    # Sets checkbox to the given value.
    #
    # @example
    #   checkbox.set?        #=> false
    #   checkbox.set
    #   checkbox.set?        #=> true
    #   checkbox.set(false)
    #   checkbox.set?        #=> false
    #
    # @param [Boolean] bool
    #

    def set(bool = true)
      assert_exists
      assert_enabled

      if @element.selected?
        @element.click unless bool
      else
        @element.click if bool
      end
    end

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

    def set?
      assert_exists
      @element.selected?
    end

    #
    # Unsets checkbox.
    #
    # Same as +set(false)+
    #

    def clear
      set false
    end

  end # CheckBox

  module Container
    def checkbox(*args)
      CheckBox.new(self, extract_selector(args).merge(:tag_name => "input", :type => "checkbox"))
    end

    def checkboxes(*args)
      CheckBoxCollection.new(self, extract_selector(args).merge(:tag_name => "input", :type => "checkbox"))
    end
  end # Container

  class CheckBoxCollection < InputCollection
    def element_class
      CheckBox
    end
  end # CheckBoxCollection
end # Watir

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
watir-webdriver-0.6.11 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.10 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.9 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.8 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.7 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.6 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.5 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.4 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.3 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.2 lib/watir-webdriver/elements/checkbox.rb