Check if a text is present in an element containing other elements

Hi,

I’m new with Katalon Recorder and I’m lost with the different commands to use and I need your help about that.

Do you know a website for helping me on the different commands proposed by the tool (withsome examples?

I would like to check if a div element contains a specific text on my page. The problem is that this div element contains also other elements. The command “verifyText” cannot do the test on the text.

Here my div:

<div class="app-title"> MyAPP<ux-badge typeclass="success" class="ng-star-inserted"><span class="ux-badge ux-badge--success ux-badge--pill ux-badge--small" data-e2e="ux-badge">myName</span></ux-badge></div>

I would like to check if the text “MyAPP” is present in the div “app-title”.

Could you please help me with that ?

Thanks in advance for you help

Hi @amadese

Please download and open it with KR and execute it.

sample-test-suite.html (1.6 KB)

The sample test case demonstrates how you can verify if an element contains a particular portion of text. It does so by:

  • Using storetText to get the innerHTML, assign it to a variable.
  • Use assertEval and execute a javascript to retrieve the variable, calling includes function on it with the expected text.

The sample test case runs directly on this forum page.

Let me know if that helps!

1 Like

Hi @ThanhTo ,

In your example above you didn’t use verifyText is it normal?

When I opened the html file, could you tell me if I have to create a new Test with the instructon defined above ?

@amadese

I didn’t use verifyText because like you said it doesn’t work well when the target element contains other elements.

You should be able to open the Test Suite and execute it immediately without further actions. The explanation above is only for your information and isn’t intended to be instructions.

If it works you you can adapt it to your own situation (replacing the target element and the text inside the includes function.

1 Like