This method is used to make visible elements contained within a DIV tag on a web page. It contains a host of properties to help manipulate the information therein.
Example of Usage
This example utilizes the main.html page that is distributed with WatiN to highlight some of the methods available with the DIV class.
''' <summary>
''' Test behavior of DIV
''' </summary>
''' <remarks>
''' currentURL is a Private Const =
''' "http://localhost:3587/main.html"
''' </remarks>
<Test()> _
Public Sub TestDiv()
Dim aDIV As Div
Dim aBoolean As Boolean = False
Using ie As IE = New IE(currentURL)
aDIV = ie.Div(Find.ById("divid"))
Assert.IsTrue(aDIV.Text.Contains("Contains text in DIV"), "Div did not contain expected text.")
Assert.IsTrue(aDIV.Tables.Length > 0, "Div did not contain a table.")
Assert.IsTrue(aDIV.Tables(0).TableRows.Length > 0, "Div table had no rows.")
Assert.IsTrue(aDIV.Tables(0).TableRows.Length = 2, "Div table did not have 2 rows.")
aString = aDIV.Tables(0).TableRows(0).TableCells(0).Text
Assert.IsTrue(aString = "Contains text in DIV", "Cell did not contain expected text.")
Assert.IsTrue(aDIV.Tables(0).TableRows(1).Text.Contains("Test label before:"), "Text not found in table row.")
Assert.IsTrue(aDIV.Tables(0).TableRows(1).TableCells(0).Text.Contains("Test label before:"), "Text not found in table cell.")
aBoolean = aDIV.Tables(0).TableRows(1).TableCells(0).CheckBoxes(0).Checked
aDIV.Tables(0).TableRows(1).TableCells(0).CheckBoxes(0).Checked = Not aBoolean
Assert.IsFalse(aBoolean = aDIV.Tables(0).TableRows(1).TableCells(0).CheckBoxes(0).Checked, "Checkbox not changed.")
End Using
End Sub
This test is pretty self-explanatory and requires little additional comment. Once the DIV is located and placed within a local variable (not required, but makes the syntax shorter on subsequent usage), the various elements within the DIV are proven to exist. The value of the checkbox is changed at the end of the test to demonstrate that this is possible.
The primary use of the DIV is to work with elements that cannot be located via the normal means available to the individual controls. For example: The text contained in the first row is not within an ASP.NET control, so it can only be examined by digging down into the table.
Contents: Table of Contents Previous Page: WatiN API Reference - Dispose Next Page: WatiN API Reference - Divs