In my cases, an offer popup randomly comes to a random page with an uncertain time.
so I want to check whether the popup is present or not before any click on the element so that I can close it and then go ahead with the rest steps.
If anyone has any idea pls help.
I was trying to use
beforeClickOn(WebElement element, WebDriver driver) **
** of AbstractWebDriverEventListener but it is not working for me.
One more thing my test Listeners are not working pls help on this.
Thank You!
Rahul
Here is something I do with alert or popup web elements I need to check that takes x amount of time before they are actually able to be checked.
I create a loop that runs x amount of times and checks on intervals if the element is present before continuing or failing.
example of for loop:
//Set Loop amount
Integer loopCount = 7
for(i = 0; i <= loopCount; i++) {
//Delay 2 seconds to give popup time to display
WebUI.delay(2)
//Check how many elements there are with given class
Integer popupCount = WebUI.executeJavaScript('return document.querySelectorAll("{Popup Class Name}").length', [])
//If there exists at least one popup, break out of for loop, else fail if loopCount is reached
if(popupCount > 0) {
break
} else if(loopCount == i) {
KeywordUtil.markFailed('Popup not detected')
}
}
The modules I imported for this is the following:
import com.kms.katalon.core.util.KeywordUtil
There are other ways of checking if the popup is visible before continuing with the script, but this is one of the most common methods I use.
If you can suggest a different approach, I can perhaps help with writing the code of that method as well
1 Like
Perhaps you can make a Keyword of your beforeClickOn() method with a few changes to add your click, such as below. This is not trying to override any method, so you can name it whatever you want, but just to allow you to check for the popup before clicking on any element/Test Object. So, now, instead of
WebUI.click(...)
you call the Keyword instead passing the Test Object same as you would do with the click.
/**
* Check for popup before clicking on element
* @param obj = a Test Object
*/
@Keyword
public beforeClickOn(TestObject obj)
{
if (WebUI.verifyElementPresent(findTestObject('LiveOffersPopUp/offerPopUp'), 10))
{
WebUI.click(findTestObject('LiveOffersPopUp/offerPopUp'))
// do we need a delay to allow the popup to disappear, like below ??
WebUI.verifyElementNotPresent(findTestObject('LiveOffersPopUp/offerPopUp'), 3))
}
WebUI.click(obj)
}
1 Like