Handle Alert

Handles alerts that appear while manipulating the browser.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Handles alerts that appear while manipulating a browser instance. It might accept or ignore all the alerts.

Script syntax

IBM RPA's proprietary scripting language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

webHandleAlert [--accept(Boolean)] [--timeout(TimeSpan)] (String)=value

Dependencies

Use the Start Browser (webStart) command to start a browser or use the Find Internet Explorer Browser (findBrowser) command to attach the Microsoft Internet Explorer before using Handle Alert (webHandleAlert) command.

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Accept accept Optional Boolean Enable to accept the alert when it appears.
Timeout timeout Opitional Time Span, Number, Text Maximum waiting time for running the command. When blank, the default timeout is 5 seconds.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Text value Text Returns the alert message.

Example

Displays an alert in the browser and then, the Handle Alert (webHandleAlert) command ignore the alert.

defVar --name alertText --type String
// Start the browser.
webStart --name browser --type "Chrome"
webNavigate --url "www.ibm.com"
// Insert an alert on the IBM  page with the message "I am an Alert!".
webExecuteJavaScript --script "window.alert(\'I am an Alert!\')"
// Ignore the alert.
webHandleAlert --timeout "00:00:10" alertText=value
// Close browser
webClose --name browser --leavebrowseropen
// Display the alert message in the console.
logMessage --message "${alertText}" --type "Info"
Note:Add a breakpoint in the line where the Handle Alert command is located to see the alert.