Weird behaviour when using keyword verifyElementVisible

happy new 2021 Katalon Team :slight_smile:

I have an issue when using the keyword “verifyElementVisible”, it always throws error in the console.
Below is the piece of code:

if(WebUI.verifyElementVisible(btn_acceptAll, FailureHandling.OPTIONAL)){

In the console log, i obtained this:

2021-01-04 09:32:45.146 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Web element with id: 'Object Repository/scr_loginFacebook/button_Accept All' located by '//button[@id='u_0_g']' not found (Root cause: com.kms.katalon.core.exception.StepFailedException: Web element with id: 'Object Repository/scr_loginFacebook/button_Accept All' located by '//button[@id='u_0_g']' not found
	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:89)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementVisibleKeyword$
	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:73)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementVisible(WebUiBuiltInKeywords.groovy:359)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementVisible$ Source)
	at authentication.facebook_auth.fb_Auth(facebook_auth.groovy:30)
	at authentication.facebook_auth.invokeMethod(facebook_auth.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.execute(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)

In my opinion, it should not throws any error in the console log. Any suggestion?

Hi @ziyaad.ellahee,

Instead of verifyElementVisible, try verifyElementPresent

if(WebUI.verifyElementPresent(btn_acceptAll, FailureHandling.OPTIONAL)){

Hope that helps. . . :smiley:

In addition, I think you should include findTestObject first before defining the object.

Try this…

if(WebUI.verifyElementPresent(findTestObject("scr_loginFacebook/button_Accept All"), wait_Time, FailureHandling.OPTIONAL)){"scr_loginFacebook/button_Accept All"))

but why when using verifyElementVisible it throws errors?

This might be the answer

Check the method signatures

  • verifyElementPresent has 2nd argument timeout. This implies verifyElementPresent implicitly retries verifying the HTML element to appear in the page until timeout-seconds expires.
  • verifyElementVisible has no timeout argument. This implies that verifyElementVisible checks the visibility of the element only once, immediately returns without any retry. If the element is slow to appear in the DOM, verifyElementVisible is likely to fail and throw an Exception.

I would rather recommend you to use BOTH.

WebUI.verifyElementPresent(TestObject ,timeout)   // wait for the element to appear in the DOM
WebUI.scrollToElement(TestObject)  // make sure the element is in the viewport
WebUI.verifyElementVisible(TestObject)  // make sure the element is visible //

This looks verbose, but is more certain.

1 Like

I have used the “waitForElementPresent” and in the log console only 1 line error is present instead of a long stack error when using “verifyElementVisible”.

“waitForElementPresent” and “verifyElementVisible” — both accept an argument of type “FailureHandling”. This determins, in case of failure, whether to throw an Exception or not.

If you have WebUI.waitForElementPresent(TestObject,timeout,FailureHandling.OPTIONAL), then you would find only 1 line error without stack trace.

If you have WebUI.waitForElementPresent(TestObject,timeout,FailureHandling.STOP_ON_FAILURE), then you would find a long stack trace output.

Please review your test case script and check how you have specified the FailureHandling parameter.

@kazurayam good point and this is what i expected but that not the case :slight_smile:
Even i used FailureHandling.OPTIONAL, i obtained a long stacktrace in the console log.

In one of my project, I tried the following code:

WebUI.waitForElementVisible(findTestObject('Page_CuraHomepage/btn_MakeAppointment2'), 10, FailureHandling.OPTIONAL)

Here I expect the Test Object btn_MakeAppointment2 will NOT appear in the DOM. When I executed, I saw the following message:

2021-01-05 21:29:25.747 DEBUG testcase.TC1_Verify Successful Login     - 4: waitForElementVisible(findTestObject("Page_CuraHomepage/btn_MakeAppointment2"), 10, OPTIONAL)
2021-01-05 21:29:38.245 INFO  c.k.k.c.webui.common.WebUiCommonHelper   - Unable to find the element located by 'By.xpath: //*[@id = 'btn-make-appointment2']'. Please recheck the objects properties to make sure the desired element is located. 
2021-01-05 21:29:38.282 WARN  k.k.c.w.k.b.WaitForElementVisibleKeyword - Web element with id: 'Object Repository/Page_CuraHomepage/btn_MakeAppointment2' located by '//*[@id = 'btn-make-appointment2']' not found

I saw only a few error messages; I did not obtain any long stack trace in the console log. I find nothing weird here.


You mentioned you still have something weird. But I could to reproduce your case on my side.