Instead of mobile.verifyElement Visible keyword, you should use mobile.waitForElementPresent keyword which will NOT throw any Exception.
Let me explain my idea by code.
The following is the implemenation of mobile.verifyElementPresent keyword:
@CompileStatic
public boolean verifyElementVisible(TestObject to, int timeout, FailureHandling flowControl) throws StepFailedException {
return MobileKeywordMain.runKeyword({
KeywordHelper.checkTestObjectParameter(to)
timeout = MobileCommonHelper.checkTimeout(timeout)
WebElement element = findElement(to, timeout)
if (element != null) {
if (element.isDisplayed()) {
logger.logPassed(MessageFormat.format(StringConstants.KW_LOG_PASSED_ELEMENT_X_VISIBLE, to.getObjectId()))
return true
} else {
MobileKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_LOG_FAILED_ELEMENT_X_VISIBLE, to.getObjectId()), flowControl, null, true)
return false
}
} else {
MobileKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_LOG_FAILED_ELEMENT_X_EXISTED, to.getObjectId()), flowControl, null, true)
return false
}
}, flowControl, RunConfiguration.getTakeScreenshotOption(), to != null ? MessageFormat.format(StringConstants.KW_MSG_FAILED_TO_CHECK_FOR_ELEMENT_X_VISIBLE, to.getObjectId()) : StringConstants.KW_MSG_FAILED_TO_CHECK_FOR_ELEMENT_VISIBLE)
}
When the target element is found missing after the timeout expires, then the verifyElementVisible keyword internally calls the MobileKeywordMain.stepFailed(...) which will throw an StepFailedExcetion. The Exception will result a long lines of stack trace printed into the console.
On the other hand, the following is the implementation of mobile.waitForElementPresent keyword:
@CompileStatic
public boolean waitForElementPresent(TestObject to, int timeout, FailureHandling flowControl) throws StepFailedException {
return MobileKeywordMain.runKeyword({
KeywordHelper.checkTestObjectParameter(to)
timeout = MobileCommonHelper.checkTimeout(timeout)
WebElement element = findElement(to, timeout)
if (element != null) {
logger.logPassed(MessageFormat.format(StringConstants.KW_LOG_PASSED_ELEMENT_PRESENTED, to.getObjectId()))
return true
} else {
logger.logWarning(MessageFormat.format(StringConstants.KW_MSG_OBJ_NOT_FOUND, to.getObjectId()))
return false
}
}, flowControl, RunConfiguration.getTakeScreenshotOption(), to != null ? MessageFormat.format(StringConstants.KW_MSG_FAILED_TO_WAIT_FOR_ELEMENT_PRESENT, to.getObjectId()) : StringConstants.KW_MSG_FAILED_TO_WAIT_FOR_ELEMENT_X_PRESENT)
}
When the target element is missing after the timeout, the keyword will call logWarning which will print a single line of message into the console; the keyword won’t call MobileKeywordMain.stepFailed(...). Therefore no Exception will be raised.