Alerts are displayed, but disappear before I can accept it

Dave-Evers, message helped me. Thanks Dave! Execute Javascript Alert Disappears

Hi there,

So finally is there a trick to “fix” the WebUI.verifyalertpresent ? I’ve the same trouble.

My script is mostly based on alert present or not in a loop to catch the alert if true and move to next iteration.

It’s broken since december. I try to fix using old version of firefox (94) but it’s not very stable.

I understand that this is due to Chrome update not Katalon but i really appreciate help on that purpose.

My code is basically :

if WebUI.verifyAlertPresent is true then gettext and move to next i
else “do that”

The following works for me:
KSE 8.2.0
Windows 10 Enterprise (64-bit)
Chrome: 97.0.4692.71 (Official Build) (64-bit)

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


//Record the AlertBtn object or 
//Create a manual AlertBtn object with XPath = //button[@onclick='alertbox()']
WebUI.waitForElementVisible(findTestObject('0.1 AlertChecks/AlertBtn'), 30, FailureHandling.OPTIONAL)'0.1 AlertChecks/AlertBtn'), FailureHandling.OPTIONAL)

if (WebUI.verifyAlertPresent(30)) {
    println('Alert is present')


I tried your code with KS v8.2.0 + Chrome 97.0.4692.71 on macOS 12.1. The Alert dialog disappeared instantly, and after 30 seconds the test case failed.

With Firefox 96.0.1 also failed.

With Safari 15.2 passed. I expected it to pass as reported previously.

I though the point is resolved by adding Chrome capabilities UnexpectedAlertBehaviour=IGNORE
no trouble since 2 days at last.

Don’t know if it will work for you all folks.


@Bailrod can you please post screenshot of your work-around?

You just need to add this option in Desired Capabilities in your project settings.

Almost 1 week without trouble since i add this.

1 Like

Sadly the desired Capabilities solution did not work for me.

However, I did notice an interesting quirk, which I managed to take advantage of. In this situation I’m automating the keypress of the delete button on my form. The alert flashed on and then off. If I now manually pressed the delete button the Alert appeared and stayed. So with that in mind, I wrote this, which works. it’s not pretty, please let me know if there’s a nicer way.

So the delete button is effectively pressed twice‘the_delete_button’))

try { WebUI.delay(2)
catch(Exception ex) {



@Katalon_team This is a very annoying problem. My test cases aren’t working anymore.

This worked for me!

@deshmukhketaki19 Legend, that’s great. perfectly works for me. Thanks a lot.

Thank you, this also help me. Very creative solution!

Interesting take. Here’s my take:

Your code may be suffering from “compensating errors” and, luckily for you, you coded it in such a way (try-catch) that the final compensation “works”. The problem with compensating errors is this:

When you fix one of the errors, the other error then appears.

My guess is, you don’t need the try-catch. You merely need to…
WebUI.waitForAlert(5) // that's a LONG time!

Of course, you may need to tinker with the timeouts, but I’d be surprised if you truly need anything else. And frankly, I couldn’t live with a try-catch like that – it’s just waiting to bite me.

Hi all,

From my Experience, we see that Katalon opened API to get running driver, based on that, we can interact with alert

Below is example:

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

//Open browser
//Navigate to your page
//Get running Driver
WebDriver myDriver = DriverFactory.getWebDriver()

//Trigger alert
WebUI.setText(findTestObject(“Object Repository/New Test Object”), “aaaa”)‘Object Repository/Page_Delete Customer/input_Customer ID_submit’))

//Accept alert


Thank you, it works for me

I came up with this, it works fine but at the end Test case fails with no Alert Found message. What is wrong here @kazurayam @Russ_Thomas @loc.nguyen @Dave_Evers @Matthew_Loo

public static boolean verifyAlertPresent(TestObject to) {
		KeywordUtil.logInfo("Inside While")
		while(!WebUI.verifyAlertPresent(3)) {
			KeywordUtil.logInfo("Alert Not Present")
			KeywordUtil.logInfo("Clicking Element")

You’re relaying on WebUI.verifyAlertPresent(3) to return a Boolean, which it does when the alert is there, but when it isn’t, it raises an exception. This seems to be the nature of most the WebUI functions that are suppose to return a Boolean.

It would have been nice if it just return a Boolean and let you decide how you want to handle it, but it doesn’t.

I have heard that if you put in the FailureHandling parameter onto the statement:
while (!WebUI.verifyAlertPresent(3, FailureHandling.OPTIONAL))

or FailureHandling.CONTINUE_ON_FAILURE

that it should return the boolean instead of faulting.

And maybe

Also, just a note that you do not return a boolean with your method, although you have indicated you want to. You need to indicate the boolean with a return statement. Currently, it should be
public static void verifyAlertPresent(TestObject to)
public static verifyAlertPresent(TestObject to)

Also, how do you prevent an infinite loop with your while statement. Perhaps you should just have it as an if statement or add some reference for how many times you want it to search for your Alert before it gives up.

1 Like

OMG, this issue is so annoying, guys. I got the same trying to refresh the page and need to accept the alert for not saving changes. I could not work around with delete button pressing.
I can try different steps to avoid this alert but again, this alert thing pisses me off

1 Like