# How to check the existence of text on the entire web page?

**URL:** <https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580>\
**Category:** Integrations\
**Tags:** integrations, katalon-studio\
**Created:** [April 29, 2018, 11:34am UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580 "2018-04-29T11:34:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tod2020](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/tod2020/32/16103_2.png) [@tod2020](https://forum.katalon.com/u/tod2020)\
**Post date:** [April 29, 2018, 11:34am UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/1 "2018-04-29T11:34:30Z")

</div>

I need to check if there is a word or phrase on the page and get:

1.true or false

2.the name or xpath of the object containing

---

<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:** [April 29, 2018, 1:12pm UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/2 "2018-04-29T13:12:14Z")

</div>

For #1 you can do the following in JavaScript:

```auto
document.body.innerText.includes("your text here")

```

Or, if the DOM API police are watching…

```auto
document.querySelector("body").innerText.includes("your text here")

```

But for #2 you’ll need a dedicated dom-walker, I believe.

---

<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:** [April 29, 2018, 1:38pm UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/3 "2018-04-29T13:38:29Z")

</div>

You want to make a Test Object with selector by XPath:

```auto
//body

```

Once this XPath expression is applied to a web page [http://demoaut.katalon.com](http://demoaut.katalon.com) , it returns such a String value:

```auto
CURA Healthcare
Home
Login
CURA Healthcare Service
We Care About Your Health
Make Appointment
CURA Healthcare Service
Atlanta 550 Pharr Road NE Suite 525
Atlanta, GA 30305
(678) 813-1KMS
info@katalon.com
Copyright © CURA Healthcare Service 2018

```

On the other hand, you want to make a Test Case with following script codes:

```auto
WebUI.openBrowser('')
WebUI.navigateToUrl('http://demoaut.katalon.com/')
def content = WebUI.getText(findTestObject('Page_Cura Healthcare Service/body'))
WebUI.verifyMatch(content, '.*Make Appointment.*', true)
WebUI.closeBrowser()

```

The Regular Expression here

```auto
.*Make Appointment.*

```

matches with ‘Make Appointment’ preceded with zero-or-more any characters and appended with zero-or-more any characters

![](https://s3.amazonaws.com/katalon-forum/editor/eh/v20vrvmb1wdt.png "Image: https://s3.amazonaws.com/katalon-forum/editor/eh/v20vrvmb1wdt.png") ![](https://s3.amazonaws.com/katalon-forum/editor/k3/4e58ibbwvo35.png)  
By this, you can determine “1. true or false” if a string ‘Make Appointment’ appears in the page.

----

You raised another problem:

> 2.the name or xpath of the object containing

I think that you can not solve this problem using the Katalon Studio’s standard keywords. All of the Katalon keywords assumes that you are aware which HTML node is of your interest in a page.  
If you want to do HTML node-tree traversal, I think you need to develop a custom keyword which performs serious DOM traversal and transformation.

---

<div class="post-metadata">

**Author:** ![tod2020](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/tod2020/32/16103_2.png) [@tod2020](https://forum.katalon.com/u/tod2020)\
**Post date:** [April 29, 2018, 3:24pm UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/4 "2018-04-29T15:24:14Z")

</div>

thx a lot)))

---

<div class="post-metadata">

**Author:** ![Caleb\_Wood](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/caleb_wood/32/4749_2.png) [@Caleb\_Wood](https://forum.katalon.com/u/Caleb_Wood)\
**Post date:** [May 2, 2018, 3:02pm UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/5 "2018-05-02T15:02:10Z")

</div>

Try using WebUI.verifyTextPresent()…make sure to set the FailureHandling.OPTIONAL tag if you want to use this in an if statement.

---

<div class="post-metadata">

**Author:** ![Kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Kai](https://forum.katalon.com/u/Kai)\
**Post date:** [August 20, 2018, 7:39am UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/6 "2018-08-20T07:39:29Z")

</div>

Below example of capture returning message when the login button was clicked.  
This helps in capturing text on the page which can be include in any point within the test cases.

> import com.kms.katalon.core.webui.driver.DriverFactory  
> import org.jsoup.Jsoup;  
> import org.jsoup.nodes.Document;  
> import org.openqa.selenium.WebDriver

> WebUI.openBrowser(‘’)  
> WebUI.navigateToUrl(‘[Login Example - Semantic](https://semantic-ui.com/examples/login.html)’)  
> WebDriver wd =DriverFactory.getWebDriver()  
> WebUI.click(findTestObject(‘Object Repository/Page\_Login Example - Semantic/div\_Login’))  
> String pageSource=wd.getPageSource()  
> Document doc = Jsoup.parse(pageSource);  
> String allText = “”;  
> elements = doc.body().select(“\*”);  
> for (Element element : elements) {  
> allText+=element.ownText()+“\n”;  
> }
> 
> ![](https://1.bp.blogspot.com/-6dHKBnHZw-c/W21SdoeQYII/AAAAAAAAAmY/zwaBtEzhFWgnMSVGGkrYCtB2jVuDpsnogCLcBGAs/s320/Untitled.jpg)
> 
> ![](https://3.bp.blogspot.com/-ZUy5mBDCyS4/W21PA4X5u8I/AAAAAAAAAmE/Ez2D87852HIceprECk-hdLImybY5HHOWwCLcBGAs/s320/text.jpg)

---

<div class="post-metadata">

**Author:** ![a.curnillon](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@a.curnillon](https://forum.katalon.com/u/a.curnillon)\
**Post date:** [July 24, 2019, 4:14pm UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/7 "2019-07-24T16:14:18Z")

</div>

Hello to everyone,  
For the first step, what about using the function `WebUI.verifyTextPresent()`? Yesterday, I use the solution give into the third message into a custom keyword but at the end, to use this function you don’t need to know where is the element right? 🤔

---

<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:29am UTC](https://forum.katalon.com/t/how-to-check-the-existence-of-text-on-the-entire-web-page/10580/9 "2022-08-08T07:29:58Z")

</div>

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


