Chuyển tới nội dung chính

JavaScript Alert Handling

A hands-on guide demonstrating how to handle JavaScript browser alerts on a real test website.

This guide shows you how to automate browser popups (JS Alerts) using a real-world testing sandbox: https://the-internet.herokuapp.com/javascript_alerts.

You will use activities including Open Browser, Click, Handle Alert, and Get Text.


What You Will Learn​

  • How to detect and accept JavaScript alert() popups that block the DOM.
  • How to extract the result message after dismissing an alert.
  • How to verify your automation worked using a Message Box.

Step-by-Step Instructions​

  1. Open akaBot Studio and create a new Process.
  2. Drag an Open Browser activity inside the main Sequence.
    • In the Properties panel under Input, set the Url field to "https://the-internet.herokuapp.com/javascript_alerts".
    • Set Browser Type to Chrome.
  3. Drag a Click activity inside the Do container of Open Browser.
    • Click Pick target element and select the button labeled Click for JS Alert on the web page.

js-alerts

  1. Drag a Handle Alert activity immediately below the Click activity.
    • Select ACCEPT from the Handle Option dropdown list in the activity block or in the Properties panel.
  2. Drag a Get Text activity below Handle Alert.
    • Click Pick target element and select the result message block below the buttons (which should display "You successfully clicked an alert").
    • Save the result to a variable alertResult (using Ctrl + K in the Result field).
  3. Place a Message Box activity below the Get Text activity to display the content of the alertResult variable.
  4. Run the process to verify that the robot successfully clicks the button, clicks OK on the popup, extracts the result text, and shows it.

tabs-alerts.png