# Verify only one text/element that present in the page

**URL:** <https://forum.katalon.com/t/verify-only-one-text-element-that-present-in-the-page/148871>\
**Category:** Web Testing\
**Created:** [October 3, 2024, 9:57am UTC](https://forum.katalon.com/t/verify-only-one-text-element-that-present-in-the-page/148871 "2024-10-03T09:57:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dummy.fairy](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dummy.fairy/32/23870_2.png) [@dummy.fairy](https://forum.katalon.com/u/dummy.fairy)\
**Post date:** [October 3, 2024, 9:57am UTC](https://forum.katalon.com/t/verify-only-one-text-element-that-present-in-the-page/148871/1 "2024-10-03T09:57:22Z")

</div>

How to verify only one text/element that can be present in the page

---

<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:** [October 3, 2024, 12:55pm UTC](https://forum.katalon.com/t/verify-only-one-text-element-that-present-in-the-page/148871/2 "2024-10-03T12:55:28Z")

</div>

Try copy&paste the following sample Test Case script into your Katalon Studio, then run it:

```auto
import org.openqa.selenium.WebElement

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import java.util.regex.Pattern
import java.util.regex.Matcher
import java.util.regex.MatchResult

TestObject makeTestObject(String id, String xpath) {
	return new TestObject(id).addProperty("xpath", ConditionType.EQUALS, xpath)
}

String url = "https://katalon-demo-cura.herokuapp.com/"

WebUI.openBrowser(url)
WebElement body = WebUI.findWebElement(makeTestObject("body", "//body"), 10)
String pageText = body.getText()
println pageText

// find all occurences of a string "Health" in the page text
Pattern ptn = Pattern.compile("Health", Pattern.CASE_INSENSITIVE)
Matcher matcher = ptn.matcher(pageText)
List<MatchResult> results = new ArrayList<>()
while (matcher.find()) {
	results.add(matcher.toMatchResult())
}

// I know, there are 4 "Health" in the page, so make sure
println "results.size()=" + results.size()
assert results.size() == 4

WebUI.closeBrowser()

```

This script checks the [https://katalon-demo-cura.herokuapp.com/](https://katalon-demo-cura.herokuapp.com/) page to have the “Health” string 4 times in the page text.

 ![スクリーンショット 2024-10-03 22.02.57](https://europe1.discourse-cdn.com/katalon/original/3X/5/b/5b86dd27ac7a244299c623b4c5f3f13176e3ff4b.jpeg)

You can change the target URL and the pattern string as you like. Of course, you want to check the string to appear only 1ce.
