FailureHandling on loops

Hello! I am trying to loop through a carousel, performing a click every time until a specific object is present. While the below works, it logs a warning to the console each time it can’t find the object. Is there a better way of handling those so that doesn’t occur?

while (WebUI.verifyElementVisible(findTestObject(btnAdd), FailureHandling.OPTIONAL) != true) {
WebUI.click(findTestObject(btnNextSlide))
}

Error logged:

2019-05-06 11:52:50.544 WARN  c.k.k.core.keyword.internal.KeywordMain  - Object 'Object Repository/Card Template/GiantEagle/btnCartAdd' is NOT visible (Root cause: com.kms.katalon.core.exception.StepFailedException: Object 'Object Repository/Card Template/GiantEagle/btnCartAdd' is NOT visible
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementVisibleKeyword$_verifyElementVisible_closure1.doCall(VerifyElementVisibleKeyword.groovy:83)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementVisibleKeyword$_verifyElementVisible_closure1.call(VerifyElementVisibleKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementVisibleKeyword.verifyElementVisible(VerifyElementVisibleKeyword.groovy:97)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementVisibleKeyword.execute(VerifyElementVisibleKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementVisible(WebUiBuiltInKeywords.groovy:358)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementVisible$5.call(Unknown Source)
	at Verify Cart Page Add to Cart Increments Campaign Spends.run(Verify Cart Page Add to Cart Increments Campaign Spends:51)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1557157939093.run(TempTestCase1557157939093.groovy:21)
)

Hi Morgan

Are you sure you want != true? Shouldn’t it be == true? (I admit, I don’t use these APIs, I find them too confusing).

Also, wouldn’t waitForElementVisible be a better choice? If the elements/images are all present in the DOM then yes, use verify. But if they’re coming from the server (usually called “lazy loading”) then I’d use waitFor…

in addition to russ advice … in theory, logged messages are triggered by raised exceptions, so enclosing the verify in a try/catch may help … or not (sometime try/catch is acting weird in test scripts).
you can give a try :slight_smile: