# Element not present/present

**URL:** <https://forum.katalon.com/t/element-not-present-present/25740>\
**Category:** Miscellaneous\
**Tags:** katalon-studio\
**Created:** [May 20, 2019, 8:41am UTC](https://forum.katalon.com/t/element-not-present-present/25740 "2019-05-20T08:41:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_Donegan](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/roger_donegan/32/16103_2.png) [@Roger\_Donegan](https://forum.katalon.com/u/Roger_Donegan)\
**Post date:** [May 20, 2019, 8:41am UTC](https://forum.katalon.com/t/element-not-present-present/25740/1 "2019-05-20T08:41:12Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [May 20, 2019, 9:17am UTC](https://forum.katalon.com/t/element-not-present-present/25740/2 "2019-05-20T09:17:40Z")

</div>

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/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/webui-verify-element-present.html)  
[https://docs.katalon.com/katalon-studio/docs/failure-handling.html#default-failure-handlingbehavior](https://docs.katalon.com/katalon-studio/docs/failure-handling.html#default-failure-handlingbehavior)

---

<div class="post-metadata">

**Author:** ![Roger\_Donegan](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/roger_donegan/32/16103_2.png) [@Roger\_Donegan](https://forum.katalon.com/u/Roger_Donegan)\
**Post date:** [May 21, 2019, 12:11pm UTC](https://forum.katalon.com/t/element-not-present-present/25740/3 "2019-05-21T12:11:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [May 21, 2019, 12:34pm UTC](https://forum.katalon.com/t/element-not-present-present/25740/4 "2019-05-21T12:34:36Z")

</div>

Can you share what you have so far?

---

<div class="post-metadata">

**Author:** ![Roger\_Donegan](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/roger_donegan/32/16103_2.png) [@Roger\_Donegan](https://forum.katalon.com/u/Roger_Donegan)\
**Post date:** [May 21, 2019, 12:56pm UTC](https://forum.katalon.com/t/element-not-present-present/25740/5 "2019-05-21T12:56:17Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [May 21, 2019, 1:36pm UTC](https://forum.katalon.com/t/element-not-present-present/25740/6 "2019-05-21T13:36:23Z")

</div>

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

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

> [@Use Code Formatting feature in your posts](http://forum.katalon.com/t/use-code-formatting-feature-in-your-posts/23550):
>
> How to format a posting text to present codes and logs nicely? Have a look at the following tutorial. Katalon Community uses [Discourse](https://www.discourse.org/) forum software.

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

```plaintext
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:

```plaintext
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…

```auto
WebUI.verifyElementText(j1z1, "something")

```

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:48am UTC](https://forum.katalon.com/t/element-not-present-present/25740/7 "2022-08-08T07:48:55Z")

</div>

Archived on August 8, 2022, 7:48am UTC


