Table of contents
1.
Introduction
2.
Alert
3.
Handle Alerts using Katalon Studio​
3.1.
Handle Accept Alert​
3.2.
Handle Dismiss Alert​
3.3.
Send data to an alert dialog
3.4.
Capture the alert message​
4.
Frequently Asked Questions
4.1.
What is the difference between an Alert and a popup?
4.2.
How do you handle toast in Katalon?
4.3.
How does Katalon handle dialog boxes?
4.4.
Which method will be used to Alert a message?
4.5.
What is the use of the alert function?
5.
Conclusion  
Last Updated: Mar 27, 2024
Medium

How to Handle Alerts with katalon studio

Author Muskan Sharma
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Readers!!

We all have come across the Alert pop-ups on a web page. They are alert messages with specific messages.

In this article, you'll learn how to handle alerts in Katalon Studio.

Let's begin!!

How to Handle Alerts

Alert

An alert in JavaScript is a specific kind of popup notification for users of the script. A dialogue box with a specified message and OK/Cancel buttons appears.

Handle Alerts using Katalon Studio

Let’s look into handling alerts using the Katalon Studio.

Handle Accept Alert

This alerting method is used to verify a user's activity. You can do it manually or automatically.

Manual Mode

  1. Launching the browser and using the Open Browser technique to navigate to the Alert current page
  2. Maximize the browser window using the command Maximize window.
  3. Press on button 
  4. Accept the Alert
Handle Accept Alert​

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser and using the Open Browser technique to navigate to the Alert current page'
WebUI.openBrowser('C:\\\\Users\\\\asus\\\\Desktop\\\\How to Handle Alerts.html')

'Maximize the browser window using the command Maximize window.'
WebUI.maximizeWindow()

'Press on button '
WebUI.click(findTestObject('Alerts/button_ClickHere'))

'Accept the Alert'
WebUI.acceptAlert()

Handle Dismiss Alert

This method is used when the user wants to cancel something.

Manual Mode

  1. Launching the browser and using the Open Browser technique to navigate to the Alert current page
  2. Maximize the browser window using the command Maximize window.
  3. Press on button 
  4. Dismissing the Alert.
Handle Dismiss Alert​

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser and using the Open Browser technique to navigate to the Alert current page'
WebUI.openBrowser('C:\\\\Users\\\\asus\\\\Desktop\\\\How to Handle Alerts.html')

'Maximize the browser window using the command Maximize window.'
WebUI.maximizeWindow()

'Press on button '
WebUI.click(findTestObject('Alerts/button_ClickHere'))

'Dissming the Alert'
WebUI.dismissAlert()

Send data to an alert dialog

The sendKeys() method allows text to be passed to an Alert text message.

Manual Mode

  1. Launching the browser and using the Open Browser technique to navigate to the Alert current page
  2. Maximize the browser window using the command Maximize window.
  3. Press on button 
  4. With the help of the sendKeys method, pass the Text to an Alert.
Send data to an alert dialog.​

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser and using the Open Browser technique to navigate to the Alert current page\r\n'
WebUI.openBrowser('C:\\\\Users\\\\asus\\\\Desktop\\Alerts\\How to Handle Alerts2.html')

'Maximize the browser window using the command Maximize window.'
WebUI.maximizeWindow()

'Press on button \r\n'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

WebDriver driver = DriverFactory.getWebDriver()

'Passing the text in the Alert\r\n'
driver.switchTo().alert().sendKeys('Testing')

'Dismissing the Alert.'
WebUI.dismissAlert()

Capture the alert message

Capture the message on Alert with the getText() method.

Manual Mode

  1. Launching the browser and using the Open Browser technique to navigate to the Alert current page
  2. Maximize the browser window using the command Maximize window.
  3. Press on button 
  4. Get the text from the Alert and store it in the Variable
  5. Verify the Actual and Expected text from the Alert
Capture the alert message​

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI


'Launching the browser and using the Open Browser technique to navigate to the Alert current page\r\n'
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\Alerts\\How to Handle Alerts2.html')

'Maximize the browser window using the command Maximize window.'
WebUI.maximizeWindow()

'Press on button \r\n'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

WebDriver driver = DriverFactory.getWebDriver()

'Get the text from the alert and store it in Variable'
String AlertText = driver.switchTo().alert().getText()

'Verify the Actual and Expected text from the Alert'
WebUI.verifyEqual(AlertText, 'Please enter your name')

Frequently Asked Questions

What is the difference between an Alert and a popup?

The window appears on the screen as a popup. A user's activities can take various forms, and those forms can all display an alert.

How do you handle toast in Katalon?

Appropriate HTML can handle the toast message.

How does Katalon handle dialog boxes?

To manage such popups as stated, you must first capture them using Katalon Studio's Object Spy tool.

Which method will be used to Alert a message?

An alert box with a specific message and an OK button are displayed via the Alert () method. When you want the information to reach the user, you can use the Alert () method.

What is the use of the alert function?

The Alert () function is a helpful built-in JavaScript feature. This feature will show text in a popup dialogue box on the screen.

Conclusion  

This blog has extensively discussed handling the alerts in Katalon Studio. This article helped enhance your knowledge about Handling Accept Alerts​ , Handling Dismiss Alerts​ , Sending data to an alert dialog and Capturing the alert message.

If you want to learn more deeply, check out the excellent content on the Coding Ninjas Website:

Solving Pop-up dialog issue with Katalon Studio 

How to Handle Textbox Checkbox and Radio Button with katalon studio 

Handling Drag and Drop in Mobile App with katalon studio

Refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. 

Refer to the links problemstop 100 SQL problemsresources, and mock tests to enhance your knowledge.

For placement preparations, visit interview experiences and interview bundle.

Thank You

Do upvote our blog to help other ninjas grow. Happy Coding!

Live masterclass