How to: Loop (while?) to check if element exist and if not - refresh page


I’m trying to establish small script which will work in loop. The case is to open webpage and check if element (defined by xpath) exist on web page. If not - lets reload webpage and check again. If not - refresh and… If element will be present - go to next step (perhaps to click it - but it’s easy ;)).

Been digging a bit and the best what I found is to work something easy like

while (WebUI.verifyElementPresent(findTestObject('test_page//button_reservation'), 1)) {    WebUI.refresh()}

But it’s returning error like

Unable to verify object 'test_page/button_reservation' is present (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'test_page/button_reservation' located by 'By.xpath: .//*[@type="submit"]' not found)

And the page is not refreshed.
My inspiration for while was script which is executed well:

int varA = 2
while (varA == true){

Would be lovely to get any suggestion

1 Like

I have the same problem. If anyone has any suggestion, will be great

1 Like

1. Pay attention to the ‘Parent iframe’

2. Pay attention to ‘Detect object by’ (just click the ensured property)

3. Try to waitForElementVisible method

4. Try to increase the timeout value

any suggestion ? i’m facing the same issue,

i’m about to loop while an object not exist, then click next button until the object exist

1 Like

You could try this:

I avoid an infinite loop by adding a counter.
I do use this in a keyword method in my tests though

int intCnt = 0

boolean booElePre = WebUI.verifyElementPresent(findTestObject(‘test_page/button_reservation’), 1)

while (!booElePre && intCnt < 5) {


booElePre = WebUI.verifyElementPresent(findTestObject(‘test_page/button_reservation’), 1)

intCnt ++


did you manage how to fix the “Unable to verify object” in your While ? experiencing same prblm. thanks