Replace value with a default if the object is not found

I have a web object which only appears for certain scenarios.
Is there a one-line command (or minimal lines) where I can check if the object is available and if not, then I can default it to a value?

Example: object is “interest payment”. For some accounts, there are no “interest payment” so it won’t appear on the web screen. I want to default it to “0.00” as I use this for a built-in calculation inside my script.

I am not too keen on having something like below as I will use it on multiple objects:

String interest_string = WebUI.getText(findTestObject(obj_interest), FailureHandling.CONTINUE_ON_FAILURE)
if (interest_string == null) {
 interest_string = "0.00"
}

You could place that code in a custom Keyword, call it safeGetText.

1 Like