Unpredictable Cookie Banner

Hello all,

I am building test case for a website that has a cookie banner that shows somewhat unpredictably. Sometimes it appears straight away or after the first click, sometimes the second or third click. I don’t know how to work around this. I tried if else statement as that logically made sense to me but I can’t see how to get it to work.

What I’m looking for is something like:

Go to URL
IF banner shows, click Accept. IF not, skip this step and move on.
Click 1
IF banner shows, click Accept. IF not, skip this step and move on.
Click 2
IF banner shows, click Accept. IF not, skip this step and move on.
Click 3
IF banner shows, click Accept. IF not, skip this step and move on.

Can somebody please help?

Thank you :slight_smile:

2 Likes

Hi @wearewattle and welcome to the Katalon Forum… We need some html code to see what you are dealing with… Please see this posting for best practices when posting help queries: [TIP] How To Help Us Help You!
Cheers Dave

2 Likes

Just a guess, but I think the banner might not appear depending on your clicks, but rather on a timer of some sort. Can you just open the URL and let it sit there for a bit? I know sometimes it appears right after you navigate anyway, but if you navigate, and the banner doesn’t show up, if you wait a bit longer does it eventually appear without any interaction from you?

2 Likes

Perhaps you can create a Keyword that surrounds your click statement with a “try/catch” block that is looking for an ElementClickInterceptedException and then do some processing like you want. So, instead of just using,
WebUI.click(findTestObject('...'))
you use the Keyword, maybe like:
CustomKeyword.'com.Tools.performClick(findTestObject('...'))

@Keyword
public void performClick(TestObject tobj) {
    try {
        WebUI.click(tobj)
    catch (ElementClickInterceptedException) {
        "IF banner shows, click Accept "
        WebUI.click(findTestObject('myPage/Accept'))
        WebUI.waitForPageLoad(10)

        WebUI.waitForElementClickable(tobj, 10)
        WebUI.click(tobj)
    }
}
4 Likes