This method is used to determine if the web page has specific text being displayed. The text to be found must be in the HTML or a label control, but cannot be located within a textbox, button or other control.
Example of Usage
This is the simplest usage of the method:
''' <summary>
''' Test behavior of ContainsText
''' </summary>
''' <remarks>
''' currentURL is a Private Const =
''' "http://localhost:3587/main.html"
''' </remarks>
<Test()> _
Public Sub TestContainsText()
Using ie As IE = New IE(currentURL)
Assert.IsTrue(ie.ContainsText("Contains text in DIV"), "Page did not contain expected text.")
End Using
End Sub
The page is examined for specified text. Frequently this is used to determine the result of some other action, such as looking for a message expected to be displayed.
This next test demonstrates that just because it can be seen, does not mean it is “contained”, or in other words, text in some controls will not be returned in the ContainsText method. The controls themselves must be examined.
''' <summary>
''' Test behavior of ContainsText
''' </summary>
''' <remarks>
''' currentURL is a Private Const =
''' "http://localhost:3587/main.html"
''' </remarks>
<Test()> _
Public Sub TestContainsText2()
Using ie As IE = New IE(currentURL)
ie.TextField(Find.ByName("textinput1")).Value = "TestContainsText"
ie.TextField(Find.ById("Textarea1")).Value = "TextAreaText"
Assert.IsFalse(ie.ContainsText("TestContainsText"), "Textbox found when not expected.")
Assert.IsTrue(ie.TextField(Find.ById("name")).Value = "TestContainsText", "Text field did not contain expected text.")
Assert.IsFalse(ie.ContainsText("Show allert"), "Button found when not expected.")
Assert.IsTrue(ie.Button(Find.ById("helloid")).Text = "Show allert", "Button did not show expected text.")
Assert.IsTrue(ie.ContainsText("Test label before"), "Label did not contain expected text.")
Assert.IsTrue(ie.ContainsText("TextAreaText"), "Text area did not contain expected text.")
Assert.IsTrue(ie.ContainsText("First Listitem"), "List item did not contain expected text.")
End Using
End Sub
This test shows how the different controls behave in relation to ContainsText calls. Controls that will return text to ContainsText include HTML controls such as TD, label controls, lists, and text areas. Controls that will not return text to ContainsText include buttons and textboxes.
Contents: Table of Contents Previous Page: WatiN API Reference - Close Next Page: WatiN API Reference - DialogWatcher