Prompt Object

Applies to TestComplete 15.10, last modified on December 15, 2021

Description

The Prompt test object corresponds to browser input boxes displayed by JavaScript prompt function. To get the prompt text, you can use the Message property. You can also use the Value property to get or set the inputted value. To close the prompt box, you can simulate a click on the OK or Cancel button.

For more information about automating prompt 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 Prompt test object, as well as the web testing functionality.

Members

Example

The following example demonstrates how to input a value in a prompt box:

JavaScript, JScript

function Prompt_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 Prompt", 10);
  link.Click();

  Log.Message("Message text: " + page.Prompt.Message);
  Log.Message("Default value: " + page.Prompt.Value);
  page.Prompt.Value = "John Smith";

  // You can also enter the value using SetText method of the input field object
  // page.Prompt.Textbox("Value").SetText("John Smith");

  page.Prompt.Button("OK").Click();
}

Python

def Prompt_Demo():
  url = "http://secure.smartbearsoftware.com/samples/testcomplete14/dialogs/"
  Browsers.Item[btIExplorer].Run(url)
  
  page = Sys.Browser().Page("*smartbear*/samples/testcomplete*/dialogs/")
  link = page.FindChild("contentText", "Show Prompt", 10)
  link.Click()
  
  Log.Message("Message text: " + page.Prompt.Message)
  Log.Message("Default value: " + page.Prompt().Value)
  page.Prompt().Value = "John Smith"

  # You can also enter the value using SetText method of the input field object
  # page.Prompt.Textbox("Value").SetText("John Smith")
  page.Prompt.Button("OK").Click()

VBScript

Sub Prompt_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 Prompt", 10)
  link.Click

  Log.Message("Message text: " & page.Prompt.Message)
  Log.Message("Default value: " & page.Prompt.Value)

  page.Prompt.Value = "John Smith"
  ' You can also enter the value using SetText method of the input field object
  ' page.Prompt.Textbox("Value").SetText("John Smith")

  page.Prompt.Button("OK").Click
End Sub

DelphiScript

procedure Prompt_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 Prompt', 10);
  link.Click();

  Log.Message('Message text: ' + page.Prompt.Message);
  Log.Message('Default value: ' + page.Prompt.Value);

  page.Prompt.Value := 'John Smith';
  // You can also enter the value using SetText method of the input field object
  // page.Prompt.Textbox('Value').SetText('John Smith');

  page.Prompt.Button('OK').Click();
end;

C++Script, C#Script

function Prompt_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 Prompt", 10);
  link["Click"]();

  Log["Message"]("Message text: " + page["Prompt"]["Message"]);
  Log["Message"]("Default value: " + page["Prompt"]["Value"]);
  page["Prompt"]["Value"] = "John Smith";

  // You can also enter the value using SetText method of the input field object
  // page["Prompt"]["Textbox"]("Value")["SetText"]("John Smith");

  page["Prompt"]["Button"]("OK")["Click"]();
}

See Also

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

Highlight search results