CheckBox Elements  

Overview

Watir::CheckBox is a very straightforward element that can be toggled on and off without many restrictions. Watir ensures it is enabled before clicking.

It is accessed by calling Browser#checkbox. Creating a CheckBoxCollection is accomplished with Browser#checkboxes. For all of the different ways of locating a CheckBox element, take a look at our Locating Elements Guide.

Checkboxes also inherit methods from standard Web Elements

Common or Special Methods

Standard Setter Interface

CheckBox#set is an alias of check and takes a boolean argument. When the value is true, Watir ensures that the element is checked. When the value is false, Watir ensures that the element is not checked.

Example

browser = Watir::Browser.start 'watir.com/examples/simple_form.html'

checkbox = browser.checkbox(id: 'interests_cars')
checkbox.checked? == false # => true
checkbox.check
checkbox.checked? == true # => true
checkbox.check
checkbox.checked? == true # => true
checkbox.clear
checkbox.checked? == false # => false

browser.close

Last Updated: March 28, 2021