If statements for actual/target comparison

Hey guys,

I’ve got following problem:
I want to compare numbers and text on a website. However, Kalaton does not recognize all values correctly with just the “Verify Element Text” method.

Example:

WebUI.verifyElementText(findTestObject(‘Leasing Privat/Page_/Gesamtbetrag des Darlehens’), ‘38198,23’)
The error message is:
Actual text ‘’ and expected text ‘38198,23’ of test object ‘Object Repository/Leasing Privat/Page_/Gesamtbetrag des Darlehens’ are NOT matched.

So I created a workaround with a getAttribute and a if-statement, which looks like this (and works):

laufleistungpa = WebUI.getAttribute(findTestObject(‘Leasing Privat/Page_/IDLaufleistung KM pa’), ‘value’)

if (laufleistungpa.equals(‘20000’)) {
WebUI.delay(1)
}

My question:

  • Is there a better solution than using WebUI.delay(1)? Something like “If the if statement is true, mark the step as successful”?
  • If you know a better solution/better workaround, I’d be happy to use it! :smile:

Thank you so much for helping me!

I mean you could use this instead if you wanted to print something to acknowledge its passed.

import com.kms.katalon.core.util.KeywordUtil as KeywordUtil

if (laufleistungpa.equals(‘20000’)) 
{
KeywordUtil.markPassed("Value is equal to 20000")
return null
}

I mean tbh, the way you have done is fine, you dont really need the if statement, you could just do something like this…

String laufleistungpa = WebUI.getAttribute(findTestObject(‘Leasing Privat/Page_/IDLaufleistung KM pa’), ‘value’)
WebUI.verifyMatch("${laufleistungpa}" , '20000', false)

ps. Verify element text should work fine for what you are attempting to do, something is wrong in your original script as the error shows you what its picking up for the first value ’ ’ so i assume your not locating the correct element.

1 Like

ps. Verify element text should work fine for what you are attempting to do, something is wrong in your original script as the error shows you what its picking up for the first value ’ ’ so i assume your not locating the correct element.

I agree with you. Anyway, I couldn’t find a solution for the verify element text problem. I tried different attributes etc, but nothing works correctly.

However, I just tested your solutions and it works perfectly fine.
Thank you so much!

1 Like

No problem, glad i could help :slight_smile:

1 Like