Element not present/present

Need some help in how to write a script for the following.

There are 4 possible element to check text from our data sheet, but only 1st of these lines will always be visible.

We want in to check if the element is present and if it is, does the text match our sheet, if the element is not present to move on to the next step and carry out the same check.

Hope I have explained properly

Any help would be gratefull appreciated

WebUI. verifyElementText ( *findTestObject (‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_1st_Zone’),First_Zone)

WebUI. verifyElementText ( findTestObject (‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_2nd_Zone’),Second_Zone)

WebUI. verifyElementText ( findTestObject (‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_3rd_Zone’),Third_Zone)

WebUI. verifyElementText ( findTestObject (‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_4th_Zone’),Fourth_Zone)

Ok so i wont write the whole script for you but i can give you some ideas that will point you in the write direction. Think about the situation you have logically.

If element A is present - do this.
Else - do this.
Else - do this
Else - do this etc…

What your trying to do is pretty common and with the help of the katalon key words im sure you will be able to do it. Ill attatch some helpful links for you to have a read from.

https://docs.katalon.com/katalon-studio/docs/control-statements.html#decision-making-statements
https://docs.katalon.com/katalon-studio/docs/webui-verify-element-present.html
https://docs.katalon.com/katalon-studio/docs/failure-handling.html#default-failure-handlingbehavior

Thanks for the reply hpulsford, 24 hours later and i am still nowhere near getting it.

Can you share what you have so far?

Not very far at all, and even this is giving an error message

WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_1st_Zone’),
First_Zone)

{
If(WebUI.verifyElementPresent(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_2nd_Zone’,FailureHandling.OPTIONAL) )==true)
{WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_3rd_Zone’), Third_Zone)))
} else {
WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_3rd_Zone’), Third_Zone)))
}

(WebUI.verifyElementPresent(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_2nd_Zone’),
}

WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_3rd_Zone’),
Third_Zone)

not_run: WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_4th_Zone’),
Fourth_Zone)

WebUI.verifyElementText(findTestObject(‘CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Ticket_Descriptions/1st_Journey_Description’),
Travel_Description)

That’s some noisy and broken-looking code you have there.

First, read this and learn how to format code in a forum post.

Next, learn how to arrange an IF/ELSE block:

if(some condition is true) {
  // do something
} else {
  // do something else
}

Placing random { and } in your code is not going to work.

Next, you can reduce some of the “noise” by using variables:

def j1z1 = findTestObject('CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_1st_Zone')

def j1z2 = findTestObject('CXP_INT/Journey_Results_Check/Multiple_Journey_Objects/Zones_Travelled_Through/1st_Journey_2nd_Zone')

Then you can…

WebUI.verifyElementText(j1z1, "something")
2 Likes