How could I create a loop that click on an element until it no longer present?

I am using a while loop to click on an element until it no longer present, below is the code I use, it works well when the element is present in the screen, but after the element disappear, the test case throws a failure of Unable to verify object ‘Object Repository/delete campus link/Page_eClass IP 2.5/delete’ is present, I have checked the Katalon document and it is written that it will return false when the element does NOT present, how could my code be modified to return false instead of throwing a failure?

 

while (WebUI.verifyElementPresent(findTestObject(‘delete campus link/Page_eClass IP 2.5/delete’), 2, FailureHandling.CONTINUE_ON_FAILURE) == true) {
WebUI.click(findTestObject(‘Object Repository/delete campus link/Page_eClass IP 2.5/delete’))

WebUI.acceptAlert()

WebUI.delay(2)
}

 

 

1 Like

I have the same problem, where I am using a while loop until element is not present and throws failure…one possible solution would be to use

FailureHandling.OPTIONAL

if that is possible in your case

Isaac Cheng said:

I am using a while loop to click on an element until it no longer present, below is the code I use, it works well when the element is present in the screen, but after the element disappear, the test case throws a failure of Unable to verify object ‘Object Repository/delete campus link/Page_eClass IP 2.5/delete’ is present, I have checked the Katalon document and it is written that it will return false whenthe element does NOT present, how could my code be modified to return false instead of throwing a failure?

while (WebUI.verifyElementPresent(findTestObject(‘delete campus link/Page_eClass IP 2.5/delete’), 2, FailureHandling.CONTINUE_ON_FAILURE) == true) {

WebUI.click(findTestObject(‘Object Repository/delete campus link/Page_eClass IP 2.5/delete’))

WebUI.acceptAlert()

WebUI.delay(2)

}

You should change your FailureHandling value to OPTIONAL

Changing Failure handling to Optional is not working

Are you guys certain you want to use verifyElementPresent? Understand that even if an element becomes invisible, it might still be present in the DOM. Try verifyElementVisible instead.