Verify Element Text inside an If condition not working

Sorry if I’m missing something obvious, but I’m trying to click on a button only if text of an element on the page is as specific value. I thought this would be straight forward but I must be doing something wrong.

My if statement looks like:

if (WebUI.verifyElementText(findTextObject(‘Object Repository/Umbrella/Invoices/Profile/Profile/Values/td_Exceptions Value’), ‘Expired’)) {

I’ve also tried:

if (WebUI.verifyElementText(findTextObject(‘Object Repository/Umbrella/Invoices/Profile/Profile/Values/td_Exceptions Value’), ‘Expired’) == true) {

in both cases I get back an error like:
groovy.lang.MissingMethodException: No signature of method: Script1551633204454.findTextObject() is applicable for argument types: (java.lang.String) values: [Object Repository/Umbrella/Invoices/Profile/Profile/Values/td_Exceptions Value]

If I run the verify element text check by itself I get a message saying they match. I thought when this was evaluated it returned either true or false?

Thanks for any help.

Well I found a workaround for now, still curious about why the info above would not work. My work around is using Get Text, saving the value to a variable and using that variable to check against the string I’m looking for in my if statement. Feels unnecessary but it works.

Hi Steven

Yep, that’s a completely valid way to do it. Think of it this way:

verifyElementText (and all its cousins) are there to perform tests (aka assertions) where, if they should fail verification, you might want to abort the test (depending on the failure handling settings) because the whole test has failed.

Since you want to consider the value found, using getText is the way to go – you’re saying, “I don’t care what the value is, just get it for me so I can consider what to do next”.

Make sense?

Makes perfect sense. Thanks Russ. Onwards and upwards :grinning:

1 Like