Thanks @grylion54. this looks good.
And I just found another way to get the OTP.
I store the the element, then extracted the OTP using this code.
WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/Page_Login/Verify_OTP/Alert_OTPSent’), 30)
GetOTP = WebUI.executeJavaScript(‘var txt = arguments[0].innerText; var numb = txt.replace(/[^0-9]/g, ''); return numb;’, Arrays.asList(element))
WebUI.setText(findTestObject(‘Object Repository/Page_Login/Verify_OTP/input_OTP_WebPatterns_wt18blockwtUsernamewtOTP_Input’),
GetOTP)