# Using VerifyElementChecked /VerifyElementNotChecked with if-Statement

**URL:** <https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [March 5, 2018, 10:24am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612 "2018-03-05T10:24:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evgeniya\_Shirmanova](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@Evgeniya\_Shirmanova](https://forum.katalon.com/u/Evgeniya_Shirmanova)\
**Post date:** [March 5, 2018, 10:24am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/1 "2018-03-05T10:24:41Z")

</div>

Hello,  
I have one problem this VerifyElementChecked /VerifyElementNotChecked.  
I have pages this checkboxes, which I must activated / deactivated.  
For example: I must deactivated a checkbox and I don’t know, it is active or not.  
Code:  
**if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1) {**  
\*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
**}**

When the checkbox is active, the test runs without problem. When the checkbox is inactive, the test is failed and I receive the error message: Test Cases FAILED because (of) Unable to verify object ‘Object Repository/TestObject’ is checked (Root cause: Object ‘Object Repository/TestObject’ is not checked).  
Is there a way to solve this Problem?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Zarashima](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/zarashima/32/928_2.png) [@Zarashima](https://forum.katalon.com/u/Zarashima)\
**Post date:** [March 5, 2018, 10:30am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/2 "2018-03-05T10:30:16Z")

</div>

> Evgeniya Shirmanova said:
> 
> Hello,  
> I have one problem this VerifyElementChecked /VerifyElementNotChecked.  
> I have pages this checkboxes, which I must activated / deactivated.  
> For example: I must deactivated a checkbox and I don’t know, it is active or not.  
> Code:  
> **if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1) {**  
> \*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
> **}**
> 
> When the checkbox is active, the test runs without problem. When the checkbox is inactive, the test is failed and I receive the error message: Test Cases FAILED because (of) Unable to verify object ‘Object Repository/TestObject’ is checked (Root cause: Object ‘Object Repository/TestObject’ is not checked).  
> Is there a way to solve this Problem?
> 
> Thank you in advance!

You need to add [FailureHandling](https://docs.katalon.com/display/KD/Failure+handling) value into this keyword. By default, the value is ‘Stop On Failure’ which will display a failed message and stop you from there.

The suggested value in this case is ‘OPTIONAL’:  
**if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1, FailureHandling.OPTIONAL) {**  
\*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
**}**

---

<div class="post-metadata">

**Author:** ![Evgeniya\_Shirmanova](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@Evgeniya\_Shirmanova](https://forum.katalon.com/u/Evgeniya_Shirmanova)\
**Post date:** [March 5, 2018, 11:02am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/3 "2018-03-05T11:02:51Z")

</div>

> Vinh Nguyen said:
> 
> > Evgeniya Shirmanova said:
> > 
> > Hello,  
> > I have one problem this VerifyElementChecked /VerifyElementNotChecked.  
> > I have pages this checkboxes, which I must activated / deactivated.  
> > For example: I must deactivated a checkbox and I don’t know, it is active or not.  
> > Code:  
> > **if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1) {**  
> > \*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
> > **}**
> > 
> > When the checkbox is active, the test runs without problem. When the checkbox is inactive, the test is failed and I receive the error message: Test Cases FAILED because (of) Unable to verify object ‘Object Repository/TestObject’ is checked (Root cause: Object ‘Object Repository/TestObject’ is not checked).  
> > Is there a way to solve this Problem?
> > 
> > Thank you in advance!
> 
> You need to add [FailureHandling](https://docs.katalon.com/display/KD/Failure+handling "Link: https://docs.katalon.com/display/KD/Failure+handling") value into this keyword. By default, the value is ‘Stop On Failure’ which will display a failed message and stop you from there.
> 
> The suggested value in this case is ‘OPTIONAL’:  
> **if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1, FailureHandling.OPTIONAL) {**  
> \*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
> **}**

Thanks you for quick response!  
In the documentation is written that return type of **verifyElementChecked /**  **verifyElementNotChecked** is boolean. If test is OK, it returns true and false otherwise.  
But I don’t get false as return value, but an exception!  
 ![](https://s3.amazonaws.com/katalon-forum/editor/07/4lz5n9rt2no7.png "Image: https://s3.amazonaws.com/katalon-forum/editor/07/4lz5n9rt2no7.png")

[param.PNG](https://s3.amazonaws.com/katalon-forum/editor/07/4lz5n9rt2no7.png)

---

<div class="post-metadata">

**Author:** ![Ananth\_raghav](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Ananth\_raghav](https://forum.katalon.com/u/Ananth_raghav)\
**Post date:** [April 6, 2018, 6:34am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/4 "2018-04-06T06:34:28Z")

</div>

**if (WebUI.verifyElementChecked(findTestObject(‘TestObject’), 1, FailureHandling.OPTIONAL) {**  
\*\* WebUI.click(findTestObject(‘TestObject’))\*\*  
\*\*}

This works! Thanks\*\*

---

<div class="post-metadata">

**Author:** ![testrightinbox1234](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/testrightinbox1234/32/16104_2.png) [@testrightinbox1234](https://forum.katalon.com/u/testrightinbox1234)\
**Post date:** [July 7, 2021, 4:46pm UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/5 "2021-07-07T16:46:28Z")

</div>

I am facing the same problem even when I have set failure handling to option.  
I am trying to verify if a checkbox is checked. If it is, it carries out further steps. If it is not checked, it first checks and then carries out those steps.  
It works fine when the checkbox is not checked. However, when the checkbox is already checked, it unchecks it instead of directly carrying out the subsequent steps. Below is my code:

if (WebUI.verifyElementChecked(findTestObject(‘Page\_CRM/Menu\_Item\_CRM’), 1, FailureHandling.OPTIONAL )) {  
WebUI.getText(findTestObject(‘Page\_CRM/Bcc\_Email’))

```
WebUI.click(findTestObject('Page_Gmail/Email_Send_now_crm'))

WebUI.closeBrowser()

```

} else {  
WebUI.check(findTestObject(‘Page\_CRM/Menu\_Item\_CRM’))

```
WebUI.getText(findTestObject('Page_CRM/Bcc_Email'))

WebUI.click(findTestObject('Page_Gmail/Email_Send_now_crm'))

WebUI.closeBrowser()

```

}

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 7, 2021, 5:27pm UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/6 "2021-07-07T17:27:27Z")

</div>

Personally, it sounds like your **if** statement is failing, however, you say it **unchecks** the element. So, how about increasing the **timeOut** factor in your **if** statement to actually give it a chance to verify. Change the 1 second to 10 seconds, like below:

```auto
if (WebUI.verifyElementChecked(findTestObject('Page_CRM/Menu_Item_CRM'), 10, FailureHandling.OPTIONAL)) {

```

---

<div class="post-metadata">

**Author:** ![testrightinbox1234](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/testrightinbox1234/32/16104_2.png) [@testrightinbox1234](https://forum.katalon.com/u/testrightinbox1234)\
**Post date:** [January 4, 2022, 10:06am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/7 "2022-01-04T10:06:26Z")

</div>

same issue even with increasing the timeOut factor.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [January 4, 2022, 3:42pm UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/8 "2022-01-04T15:42:09Z")

</div>

Then how about confirming that the checkbox is not checked.

```auto
if (WebUI.verifyElementChecked(findTestObject('Page_CRM/Menu_Item_CRM'), 10, FailureHandling.OPTIONAL )) {
    WebUI.getText(findTestObject('Page_CRM/Bcc_Email'))

    WebUI.click(findTestObject('Page_Gmail/Email_Send_now_crm'))

} else {
    WebUI.verifyElementNotChecked(findTestObject('Page_CRM/Menu_Item_CRM'), 10, FailureHandling.OPTIONAL )
    
    WebUI.check(findTestObject('Page_CRM/Menu_Item_CRM'))

    WebUI.getText(findTestObject('Page_CRM/Bcc_Email'))

    WebUI.click(findTestObject('Page_Gmail/Email_Send_now_crm'))

}

WebUI.closeBrowser()

```

---

<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:30am UTC](https://forum.katalon.com/t/using-verifyelementchecked-verifyelementnotchecked-with-if-statement/9612/9 "2022-08-08T07:30:06Z")

</div>

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


