Confirm Object

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

The Confirm test object corresponds to a web browser’s message box with two buttons to select from. Examples include:

  • Confirmation boxes displayed by the JavaScript confirm function.

  • Message boxes displayed by the onbeforeunload event handler when the user leaves the page.

  • Message boxes asking whether to resubmit forms when the user reloads the web page.

You can get the message text using the Message property and close the message box by simulating a click on the OK or Cancel button.

For more information on automating these message boxes, see Handle 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 Confirm test object, as well as the web testing functionality.

Members

Example

The following example demonstrates how to click the OK button in a confirmation box:

JavaScript, JScript

function Confirm_Demo()
{
  var url = "http://secure.smartbearsoftware.com/samples/testcomplete15/dialogs/";
  Browsers.Item(btIExplorer).Run(url);

  var page = Sys.Browser().Page("*smartbear*/samples/testcomplete*/dialogs/");
  var link = page.FindChild("contentText", "Show Confirm", 10);
  link.Click();

  Log.Message("Message text: " + page.Confirm.Message);
  page.Confirm.Button("OK").Click();
}

Python

VBScript

Sub Confirm_Demo()
  url = "http://secure.smartbearsoftware.com/samples/testcomplete15/dialogs/"
  Browsers.Item(btIExplorer).Run(url)

  Set page = Sys.Browser().Page("*smartbear*/samples/testcomplete*/dialogs/")
  Set link = page.FindChild("contentText", "Show Confirm", 10)
  link.Click

  Log.Message("Message text: " & page.Confirm.Message)
  page.Confirm.Button("OK").Click
End Sub

DelphiScript

procedure Confirm_Demo();
var url, page, link;
begin
  url := 'http://secure.smartbearsoftware.com/samples/testcomplete15/dialogs/';
  Browsers.Item(btIExplorer).Run(url);

  page := Sys.Browser().Page('*smartbear*/samples/testcomplete*/dialogs/');
  link := page.FindChild('contentText', 'Show Confirm', 10);
  link.Click();

  Log.Message('Message text: ' + page.Confirm.Message);
  page.Confirm.Button('OK').Click();
end;

C++Script, C#Script

function Confirm_Demo()
{
  var url = "http://secure.smartbearsoftware.com/samples/testcomplete15/dialogs/";
  Browsers["Item"](btIExplorer)["Navigate"](url);

  var page = Sys["Browser"]()["Page"]("*smartbear*/samples/testcomplete*/dialogs/");
  var link = page["FindChild"]("contentText", "Show Confirm", 10);
  link["Click"]();

  Log["Message"]("Message text: " + page["Confirm"]["Message"]);
  page["Confirm"]["Button"]("OK")["Click"]();
}

See Also

Testing Web Applications
Handle JavaScript Popups and Browser Dialogs
Alert Object
Prompt
Login Object

Highlight search results