Dynamic pop up handling

How to handle the pop up dynamically? I am automating a website and i don’t know when the pop up will appear ,in this case how should i handle those pop ups?

I use an if statement to handle these:

if (WebUI.verifyElementPresent(findTestObject(‘something like popup label object’),

3, FailureHandling.OPTIONAL)) {

WebUI.click(findTestObject('button_OK'), 

    FailureHandling.CONTINUE\_ON\_FAILURE)

}

in this case it will check for 3 seconds if the popup is there. It’s optional so if it fails it doesn’t fail the test. If it is there it clicks the ok to close it and continues on failure. This second part will log as failed because it’ continues on failure and is not optional.

you can put anything you want inside.

Hope this helps.

Hey thanks for the suggestion. This will not work in my case.

Hey Bhargava,

I am looking for similar solution for pop up where pop up will appear on page at any instance.

Any suggestion/solution would be helpful.

Thanks

bhargava you mentioned this would not work for you? You maybe able to write this as a keyword and call the method in after each step. Surely there is some action required for the popup to occur?

I had the same issue, it would kill my scripts!!! I also didn’t want them to ‘fail’ when the popup displayed, so I created a warning. This way the script continues running whether or not the popup comes up and the NO button is clicked.

I’m using the code below to handle an intermittent popup. It occurs (if it’s gong to) 8 secs. after the homepage is drawn so I added a 10 sec. delay (according to my IT folks). This makes it slow, but it works.

You will need to ‘force’ the popup object (in my case ‘Your Opinion Matters’) to appear in order to capture the object. I did so by talking to my IT people and using a .url where it will always show. (It’s challenging to capture and test randomly)! I used object spy to capture the ‘no’ button on the popup (my desired response to the popup to then return to the homepage and carry on running the script). Then, I was 80% there. Here’s the code I used. It’s a little slow, and I would prefer a method to block popups, but in lieu of this, it does the trick. If you are using manual mode because you are more comfortable there, you can copy this into the script view and save to see what it looks like.

First: Expand the import static list at the top of your scripts and add this line:
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil

Add this code in script view and replace the test object with the one you’ve captured (the popup object).

Script view:

// Code to handle popup on home page

elementPresent = WebUI.waitForElementPresent(findTestObject(‘HomePage - Your Opinion Matters/Page_Southern New Hampshire Univers/button_NO’),

10)

if (elementPresent == true) {

WebUI.click(findTestObject('HomePage - Your Opinion Matters/Page\_Southern New Hampshire Univers/button\_NO'))

} else {

KeywordUtil.markWarning('Pop Up Did Not Display...Continue Execution')

}

WebUI.comment(’***** End popup handler *****’)

1 Like