Description
The Alert
test object corresponds to alerts displayed in web browsers using the JavaScript alert
function. You can get the alert text using the Message
property and close the alert by simulating a click on its child OK button.
For more information on automating JavaScript alerts, see Handling JavaScript Popups and Browser Dialogs.
Requirements
-
A license for TestComplete Web module.
-
The Web Testing plugin. This plugin is installed and enabled automatically. The plugin implements the
Alert
test object, as well as the web testing functionality.
Members
Example
The following example demonstrates how to log the alert text and close the alert:
JavaScript, JScript
function Test()
{
var url = "http://downloads.smartbear.com/samples/testcomplete10/dialogs/";
Browsers.Item(btIExplorer).Run(url);
var page = Sys.Browser("*").Page(url);
page.Wait();
var link = page.FindChild("contentText", "Show Alert", 10);
link.Click();
Log.Message("Alert text: " + page.Alert.Message);
page.Alert.Button("OK").Click();
}
Python
def Test():
url = "http://downloads.smartbear.com/samples/testcomplete10/dialogs/"
Browsers.Item[btIExplorer].Run(url)
page = Sys.Browser("*").Page(url)
page.Wait()
link = page.FindChild("contentText", "Show Alert", 10)
link.Click()
Log.Message("Alert text: " + page.Alert().Message)
page.Alert().Button("OK").Click()
VBScript
Sub Test
Dim url, page, link
url = "http://downloads.smartbear.com/samples/testcomplete10/dialogs/"
Browsers.Item(btIExplorer).Run url
Set page = Sys.Browser("*").Page(url)
page.Wait()
Set link = page.FindChild("contentText", "Show Alert", 10)
link.Click
Log.Message "Alert text: " + page.Alert.Message
page.Alert.Button("OK").Click
End Sub
DelphiScript
procedure Test;
var url, page, link;
begin
url := 'http://downloads.smartbear.com/samples/testcomplete10/dialogs/';
Browsers.Item[btIExplorer].Run(url);
page := Sys.Browser('*').Page(url);
page.Wait();
link := page.FindChild('contentText', 'Show Alert', 10);
link.Click;
Log.Message('Alert text: ' + page.Alert.Message);
page.Alert.Button('OK').Click;
end;
C++Script, C#Script
function Test()
{
var url = "http://downloads.smartbear.com/samples/testcomplete10/dialogs/";
Browsers["Item"](btIExplorer)["Run"](url);
var page = Sys["Browser"]("*")["Page"](url);
page["Wait"]();
var link = page["FindChild"]("contentText", "Show Alert", 10);
link["Click"]();
Log["Message"]("Alert text: " + page["Alert"]["Message"]);
page["Alert"]["Button"]("OK")["Click"]();
}
See Also
Testing Web Applications
Handling JavaScript Popups and Browser Dialogs
Confirm Object
Prompt Object
Login Object