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 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
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 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 Prompt", 10);
btn.Click();
Log.Message("Prompt: " + 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 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 Prompt", 10)
btn.Click()
Log.Message("Prompt: " + 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 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 Prompt", 10)
btn.Click
Log.Message("Prompt: " + 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 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 Prompt', 10);
btn.Click;
Log.Message('Prompt: ' + 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 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 Prompt", 10);
btn["Click"]();
Log["Message"]("Prompt: " + 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
Handling JavaScript Popups and Browser Dialogs
Alert Object
Confirm Object
Login Object