How to work better with Browser Alerts with custom keywords?
Have you ever encountered a situation where you were unable to successfully complete activities on a browser alert because it disappeared too quickly?
If yes, then please find the custom keyword provided below
The solution is a custom keyword that you can put under the “Keywords“ folder of the Katalon Projects
KatalonAlert.groovy (6.8 KB)
Accepting Next Alert pop-up and Verify present Alert:
// Accept the next confirm popup
CustomKeywords.'KatalonAlert.acceptNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
// Verify alert present
CustomKeywords.'KatalonAlert.handleNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
CustomKeywords.'KatalonAlert.verifyAlertPresent'()
-
Please note that the keyword
acceptNextAlertmust be called before we trigger the alert (e.g. click login button) or if you want to usea verify keyword, then you have to call one ofhandleNextAlert,acceptNextAlert,denyNextAlertbefore the alert trigger as well. -
There must be no delay between the alert trigger (e.g. click login button) and the verify keyword (e.g. verifyAlertPresent). For example, the below script will produce an error:
CustomKeywords.'KatalonAlert.acceptNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
WebUI.delay(3) // Don't delay here
CustomKeywords.'KatalonAlert.verifyAlertPresent'()
Let us know if the custom keywords that we have provided works for you. And if they do, then don’t forget to show us some love by clicking on the like button below
!
And feel free to leave us your feedback so that we could improve our articles in the future!
We also have other topics related to working with custom keywords in Katalon Studio, check them out below ![]()
How to use the Windows.switchToDesktop() custom keyword to switch window faster?
How to use the WebUI.setText() custom keyword successfully?
How to use the WebUI.dragAndDropToObject custom keyword successfully?
How to work better with Browser Alerts? → You are here

