The Checkbox method allows access to checkboxes on the web page, as you might expect. As with most controls that WatiN exposes, most of the properties are read only, such as text, tag name, etc.
The primary purpose of the method is to allow WatiN to examine the current value or to check or uncheck the value of a checkbox.
Example of Usage
''' <summary>
''' Test behavior of checkboxes.
''' </summary>
''' <remarks>
''' currentURL is a Private Const =
''' "http://localhost:3587/main.html"
''' CheckboxOne is a Private Const = "Checkbox1"
''' </remarks>
<Test()> _
Public Sub TestCheckbox()
Using ie As IE = New IE(currentURL)
Dim aCheckboxValue As Boolean = False
aCheckboxValue = ie.CheckBox(Find.ById(New Regex(CheckboxOne))).Checked
ie.CheckBox(Find.ById(New Regex(CheckboxOne))).Checked = Not aCheckboxValue
Assert.AreNotEqual(aCheckboxValue, ie.CheckBox(Find.ById(New Regex(CheckboxOne))).Checked, "Checkbox did not change value.")
ie.CheckBox(Find.ById(New Regex(CheckboxOne))).Checked = aCheckboxValue
Assert.AreEqual(aCheckboxValue, ie.CheckBox(Find.ById(New Regex(CheckboxOne))).Checked, "Checkbox did not reset to original value.")
End Using
End Sub
This test merely saves the current state of the checkbox being tested, and then changes the value to show it can, finally restoring it to its original state.
It is generally considered good testing practice to return the web page or the database, if changes are made there, to its original state after a test, to ensure that the test can be run over and over with the expected results not corrupted by prior tests.
Contents: Table of Contents Previous Page: WatiN API Reference - CaptureWebPageToFile Next Page: WatiN API Reference - CheckBoxes