Sha256: c7a911516114ca2766f45f48350d04787b460716ae680b06b02bbcdd454951c9

Contents?: true

Size: 1.18 KB

Versions: 37

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8

module Watir
  class CheckBox < Input

    #
    # Set this checkbox to the given value
    #
    # Example:
    #
    #   checkbox.set?        #=> false
    #   checkbox.set
    #   checkbox.set?        #=> true
    #   checkbox.set(false)
    #   checkbox.set?        #=> false
    #

    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

    #
    # Unset this 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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
watir-webdriver-0.6.1 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.6.0 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.8 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.7 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.6 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.5 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.4 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.3 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.2 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.1 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.5.0 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.4.1 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.4.0 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.9 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.8 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.7 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.6 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.5 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.4 lib/watir-webdriver/elements/checkbox.rb
watir-webdriver-0.3.3 lib/watir-webdriver/elements/checkbox.rb