C#
// *** Browser control below
// Some test cases may require that all cookies be cleared ahead of time.
// WebAii does not care but depending on your environment and your specific
// test case you may care.
ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.Cookies);
// Navigate to an explicit URL
// Navigate to a relative URL. The preceeding ~ means to use the
// baseURL setting stored in the app.config file
ActiveBrowser.NavigateTo("~/videosearch");
// Let's check the title
string pageTitle = ActiveBrowser.PageTitle;
Assert.AreEqual("Video Search Page", pageTitle, "Actual page title = \"{0}\"", pageTitle);
// Backup to the previous web page
ActiveBrowser.GoBack();
// Return to the next web page after previous
ActiveBrowser.GoForward();
// Refresh the current web page
ActiveBrowser.Refresh();
// After performing a mouse click you may need to explicitly wait
// for the browser to be ready. You very rarely would need to
// call this function when using the Actions methods.
Desktop.Mouse.Click(MouseClickType.LeftClick, 300, 275);
ActiveBrowser.WaitUntilReady();
// Scroll the browser window in order to make some element visible
ActiveBrowser.ScrollBy(225, 170); // Scrolls right 220 and down 170 pixels
ActiveBrowser.ScrollBy(-225, -170); // Scrolls left 200 and up 170 pixels
// *** Find elements below
// an input textbox
Element input1 = ActiveBrowser.Find.ById("input1");
// a textarea
Element textArea = ActiveBrowser.Find.ById("textarea1");
// an input radio button
Element inputradio = ActiveBrowser.Find.ById("inputradio");
// an input check box
Element inputcheck = ActiveBrowser.Find.ById("inputcheck");
// an input dropdown
Element selection = ActiveBrowser.Find.ById("selection");
// *** DOM actions below
// set the text of the input1 textbox to 'test1'
ActiveBrowser.Actions.SetText(input1, "test1");
// set the text of the textarea1 to 'test2'
ActiveBrowser.Actions.SetText(textArea, "test2");
// set the input radio button to selected
ActiveBrowser.Actions.Check(inputradio, true);
// set the input checkbox to selected
ActiveBrowser.Actions.Check(inputcheck, true);
// set the dropdown to item index 4
ActiveBrowser.Actions.SelectDropDown(selection, 4);
// set the dropdown to item with text='one1'
ActiveBrowser.Actions.SelectDropDown(selection, "one1");
// set the dropdown to item with value='test'
ActiveBrowser.Actions.SelectDropDown(selection, "test", true);
// the currently selected text should be the dropdown selection
string textSelected = ActiveBrowser.GetSelectedText();
Assert.AreEqual("test", textSelected, "Actual test is \"{0}\"", textSelected);
Visual Basic
' *** Browser control below
' Navigate to an explicit URL
' Navigate to a relative URL. The preceeding ~ means to use the
' baseURL setting stored in the app.config file
ActiveBrowser.NavigateTo("~/videosearch")
' Let's check the title
Dim pageTitle As String = ActiveBrowser.PageTitle
Assert.AreEqual("Video Search Page", pageTitle, "Actual page title = ""{0}""", pageTitle)
' Now go back.
ActiveBrowser.GoBack()
Assert.IsTrue(ActiveBrowser.Url.Contains("Browser.htm"))
' Now go forward
ActiveBrowser.GoForward()
Assert.IsTrue(ActiveBrowser.Url.Contains("google.com"))
' Do a Refresh()
ActiveBrowser.Refresh()
Assert.IsTrue(ActiveBrowser.Url.Contains("google.com"))
' *** Find elements below
' an input textbox
Dim input1 As Element = ActiveBrowser.Find.ById("input1")
Assert.IsTrue((input1.ElementType = ElementType.Input))
' a textarea
Dim textArea As Element = ActiveBrowser.Find.ById("textarea1")
Assert.IsTrue((textArea.ElementType = ElementType.TextArea))
' an input radio button
Dim inputradio As Element = ActiveBrowser.Find.ById("inputradio")
Assert.IsTrue((inputradio.ElementType = ElementType.Input))
' an input check box
Dim inputcheck As Element = ActiveBrowser.Find.ById("inputcheck")
Assert.IsTrue((inputcheck.ElementType = ElementType.Input))
' a select dropdown
Dim selection As Element = ActiveBrowser.Find.ById("selection")
Assert.IsTrue((selection.ElementType = ElementType.Select))
' a table
Dim mainTable As Element = Find.ById("mainTable1")
Assert.IsTrue((mainTable.ElementType = ElementType.Table))
' *** DOM actions below
' Now set the text for the text box
Actions.SetText(Find.Elements("MyTextBox"), "This is a TEST for TextBox!")
' Now set the text for the text area.
Actions.SetText(Find.Elements("MyTextArea"), "This is a TEST for TextArea!")
' Check the checkbox
Actions.Check(checkBox, True)
' Uncheck the radio button
Actions.Check(radio, False)
' Select using Value
Actions.SelectDropDown(selection, "2", True)
' Select using the item text.
Actions.SelectDropDown(selection, "One")
' Select using index
Actions.SelectDropDown(selection, 2)
' the currently selected text should be the dropdown selection
Dim textSelected As String = ActiveBrowser.GetSelectedText()
Assert.AreEqual("test", textSelected, "Actual test is ""{0}""", textSelected)