How to apply condition if element is not present

how to add condition to check if an element is present and if it is not present, another action should be done.

Who can help on that?

Have you try?

if WebUI.waitforElementPresent(to,timeout) {
//Do This}
else {
//Do That}

MaKatalon said:

Have you try?

if WebUI.waitforElementPresent(to,timeout) {
//Do This}
else {
//Do That}

here is my code:

if(WebUI.waitForElementPresent(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/Pending Work Items’),0)){

WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/Pending Work Items’))

}

else{

WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/a_Sign out’))

}

it does not work :frowning:
it does not do the sign out

Ziyaad said:

MaKatalon said:

Have you try?

if WebUI.waitforElementPresent(to,timeout) {
//Do This}
else {
//Do That}

here is my code:

if(WebUI.waitForElementPresent(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/Pending Work Items’),0)){

WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/Pending Work Items’))

}

else{

WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/a_Sign out’))

}

it does not work :frowning:
it does not do the sign out

it work now, i just tested it and there was a timeout now the same code work…
Thank you mate :slight_smile:

Good to hear that.

1 Like

MaKatalon said:

Good to hear that.

Yes, at first i have lots of pressure when i start using Katalon, but now, i have been granted enough time to explore the tool to the maximum.

However, i wanted to know is it possible to assign a for example for the line below, to put into a variable?:

Original:
WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/a_Sign out’)

**If possible like this:

**def = WebUI.click(findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/a_Sign out’)
Hope to hear from you soon?

Not sure what you intend to do, why do you need an action to be a variable ? WebUi.Click is an action .

Indeed WebUI.Click is an action and i made a mistake in my question…However, i wanted to check if this one is feasible:

def X = findTestObject(‘Memority_V1/Approve Internal Identity/Approve Internal Identity Home/a_Sign out’)

and then perform an If condition with X.

Yes, findTestObject returns a TestObject as its return value when it found the test object. You can assign it to a TestObject variable.
But, take note that the return value that you going to assigned into the Variable is a TestObject, it is not a ‘condition’ that you can directly utilized in your ‘if else’ statement.

Here is my IF condition:

if (WebUI.verifyElementPresent(a, 10) || WebUI.verifyElementPresent(b, 10)) {

WebUI.click(findTestObject('Memority\_V1/Create Internal Identity/Create Internal Identity/button\_Cancel')) 

} else {

WebUI.verifyElementPresent(findTestObject('Memority\_V1/Create Internal Identity/Create Internal Identity Home/input\_The task has been taken'))



WebUI.click(findTestObject('Memority\_V1/Create Internal Identity/Create Internal Identity Home/input\_The task has been taken'))

}

The problem is that it always failed when doing the IF and the IF in my current state should be false.

How can i solved this problem?

Hi Ziyaad,
showing the error you encounter would help to understand better on the problem.