Confirm Object

Applies to TestComplete 14.30, last modified on November 21, 2019

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 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 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 Test()
{
  var url = "http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/";

  Browsers.Item(btIExplorer).Run(url);
  var page = Sys.Browser("*").Page("*smartbear*/samples/testcomplete*/dialogs/");
  page.Wait();

  var btn = page.FindChild("contentText", "Show Confirm", 10);
  btn.Click();

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

Python

def Test():
  url = "http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/"

  Browsers.Item[btIExplorer].Run(url)
  page = Sys.Browser("*").Page("*smartbear*/samples/testcomplete*/dialogs/")
  page.Wait()

  btn = page.FindChild("contentText", "Show Confirm", 10)
  btn.Click()

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

VBScript

Sub Test
  Dim url, page, btn

  url = "http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/"
  Browsers.Item(btIExplorer).Run url
  Set page = Sys.Browser("*").Page("*smartbear*/samples/testcomplete*/dialogs/")
  page.Wait()

  Set btn = page.FindChild("contentText", "Show Confirm", 10)
  btn.Click

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

DelphiScript

procedure Test;
var url, page, btn;
begin
  url := 'http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/';

  Browsers.Item[btIExplorer].Run(url);
  page := Sys.Browser('*').Page('*smartbear*/samples/testcomplete*/dialogs/');
  page.Wait();

  btn := page.FindChild('contentText', 'Show Confirm', 10);
  btn.Click;

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

C++Script, C#Script

function Test()
{
  var url = "http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/";

  Browsers["Item"](btIExplorer)["Run"](url);
  var page = Sys["Browser"]("*")["Page"]("*smartbear*/samples/testcomplete*/dialogs/");
  page["Wait"]();

  var btn = page["FindChild"]("contentText", "Show Confirm", 10);
  btn["Click"]();

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

See Also

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

Highlight search results