# How to use if to compare boolean type true and string type true? Can the boolean type be converted to a string type?

**URL:** <https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [July 30, 2021, 9:05am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098 "2021-07-30T09:05:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1968693027](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/1968693027/32/18174_2.png) [@1968693027](https://forum.katalon.com/u/1968693027)\
**Post date:** [July 30, 2021, 9:05am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098/1 "2021-07-30T09:05:23Z")

</div>

How to use if to compare boolean type true and string type true? Can the boolean type be converted to a string type?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 30, 2021, 9:57am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098/2 "2021-07-30T09:57:30Z")

</div>

Please show us what you have done. Show us what you expected to see and what actually saw. Please show us your code.

---

<div class="post-metadata">

**Author:** ![1968693027](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/1968693027/32/18174_2.png) [@1968693027](https://forum.katalon.com/u/1968693027)\
**Post date:** [July 30, 2021, 10:39am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098/3 "2021-07-30T10:39:32Z")

</div>

![image](https://europe1.discourse-cdn.com/katalon/original/3X/6/6/665c548450230a4feca3b172328314983f815ce3.png)  
 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/c/6/c6d4256ef0fdf7aea87a9692f7a354b93c0eff56.png)  
is\_present is the false returned by verify element present, it is of Boolean type,  
findTestData(‘Deploy/OverlayNetwork/Lan\_Interface/Add\_OverlayLan’).getValue(15, index)) {  
The result of WebUI.click(findTestObject(‘Page\_IO Controller WAN/deploy/overlay\_network/lan\_interface/btn\_OverlayLan\_Vrrp’)) is also false, but it is a string type, so the result of the comparison between the two is not equal, but I hope they are equal

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 30, 2021, 11:27am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098/4 "2021-07-30T11:27:19Z")

</div>

`java.lang.Boolean.valueOf(String)` returns boolean value. For example, the following code would be what you want.

```auto
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

boolean is_present = false

String findTestDataResult = "false"

if (is_present == findTestDataResult) {
	WebUI.comment("1st challenge: equal")
} else { 
	WebUI.comment("1st challenge: not equal")
}

boolean evaluated = Boolean.valueOf(findTestDataResult)
if (is_present == evaluated) {
	WebUI.comment("2nd challenge: equal")
} else {
	WebUI.comment("2nd challenge: not equal")
}

```

---

<div class="post-metadata">

**Author:** ![1968693027](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/1968693027/32/18174_2.png) [@1968693027](https://forum.katalon.com/u/1968693027)\
**Post date:** [July 30, 2021, 11:47am UTC](https://forum.katalon.com/t/how-to-use-if-to-compare-boolean-type-true-and-string-type-true-can-the-boolean-type-be-converted-to-a-string-type/57098/5 "2021-07-30T11:47:32Z")

</div>

> [@kazurayam](#):
>
> import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI boolean is\_present = false String findTestDataResult = “false” if (is\_present == findTestDataResult) { WebUI.comment(“1st challenge: equal”) } else { WebUI.comment(“1st challenge: not equal”) } boolean evaluated = Boolean.valueOf(findTestDataResult) if (is\_present == evaluated) { WebUI.comment(“2nd challenge: equal”) } else { WebUI.comment(“2nd challenge: not equal”) }

thank you ， i try
