verifyElementVisible is not working in If statement


#1

Hi,

I am using verifyElementVisible in If statement but it does not work if object if object is not present.
Code:-

def errorMsg1 = Mobile.verifyElementVisible(findTestObject(‘Object Repository/LMO_LoginPg/ErrorMessage1’), 5)

if (errorMsg1 == true)

{

Mobile.tap(findTestObject(‘Object Repository/LMO_LoginPg/ErrorMessage1’), 5)

}
else

{

CustomKeywords.‘writeDataToExcel.WriteDataToExcelSheet.WriteDatatoDataFile’(username, 3)

Mobile.takeScreenshot(‘C:\\Alok\\KatalonStudio_LMO\\LMO\\Test Cases\\Screenshots\\Login_LoginSuccssful.png’)

}

When object ‘Object Repository/LMO_LoginPg/ErrorMessage1’ is not visible, the code does not go to else part. It shows error message.
Error message:-
Test1 FAILED because (of) Failed to check for element 'Object Repository/LMO_LoginPg/errorMsg1 ’ visible (Root cause: Element 'Object Repository/LMO_LoginPg/errorMsg1 ’ not found)

Can someone tell me whether I have missed anything here and reason for getting this message?


#2

It looks like you need to modify the default failure handling (third argument to verifyElementVisible).

https://docs.katalon.com/display/KD/Failure+handling

Set it to Optional.


#3

Thanks, It is working for me