# WS.verifyElementText

**URL:** <https://forum.katalon.com/t/ws-verifyelementtext/88275>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 18, 2023, 1:33pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275 "2023-05-18T13:33:51Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 18, 2023, 1:33pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/1 "2023-05-18T13:33:51Z")

</div>

Hi there,  
I need to verify this S using this:

response = WS.sendRequestAndVerify(findTestObject(‘OR\_ws03’))  
WS.verifyElementText(response, ‘GenWs03ConsultadeDeudaCC.ExecuteResponse.Buenpaga’, ‘S’)  
but the test failed , this is a message: Expected text is ‘S’ but actual element text is unable to verify  
Any help? Thank you in advance

\<SOAP-ENV:Envelope xmlns:SOAP-ENV=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)” xmlns:xsd=“[XML Schema](http://www.w3.org/2001/XMLSchema)” xmlns:SOAP-ENC=“[http://schemas.xmlsoap.org/soap/encoding/](http://schemas.xmlsoap.org/soap/encoding/)” xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
SOAP-ENV:Body  
\<GenWs03ConsultadeDeudaCC.ExecuteResponse xmlns=“GeoTribUy”\>  
S  
  
\<SDT\_ColeccionCobranzaItem\>  
N  
S  
2023  
19/07/23  
301  
CHAPA  
  
703.00  
1  
\</SDT\_ColeccionCobranzaItem\>  
  
\</GenWs03ConsultadeDeudaCC.ExecuteResponse\>  
\</SOAP-ENV:Body\>  
\</SOAP-ENV:Envelope\>

---

<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:** [May 18, 2023, 2:01pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/2 "2023-05-18T14:01:49Z")

</div>

> [@daimilamoru2018](#):
>
> I need to verify this S

This single line is very ambiguous. I do not see what you want to do.

* * *

Your code

```auto
WS.verifyElementText(response, ‘GenWs03ConsultadeDeudaCC.ExecuteResponse.Buenpaga’, ‘S’)

```

expects that your SOAP Response XML would have the code like

```auto
...
<GenWs03ConsultadeDeudaCC>
    <ExecuteResponse>
        <Buenpaga>S<Buenpaga>
    </ExecuteResponse>
</GenWs03ConsultadeDeudaCC>
...

```

but the code you showed to us does not contain such code. So your test fails inevitably.

---

<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:** [May 18, 2023, 2:10pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/3 "2023-05-18T14:10:20Z")

</div>

@daimilamoru2018

You shoud read the doc carefully.

[https://docs.katalon.com/docs/create-tests/keywords/keyword-description-in-katalon-studio/web-service-keywords/ws-verify-element-text](https://docs.katalon.com/docs/create-tests/keywords/keyword-description-in-katalon-studio/web-service-keywords/ws-verify-element-text)

> Katalon checks if the XML element content text is strictly equal to the expected value. For example, if there is whitespace after the `Approved` value, you need to add it to the third argument as follows:

I am afraid that this keyword has very limited usability. It may not be useful for you.

---

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 18, 2023, 4:09pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/4 "2023-05-18T16:09:35Z")

</div>

Thank you very much for your response. What I want to verify is that the value in this tag is “S”. This is my XML

```auto
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
    <GenWs03ConsultadeDeudaCC.ExecuteResponse xmlns="GeoTribUy">
      <Buenpaga>S</Buenpaga>
      <Sdtcoleccioncobranza>
        <SDT_ColeccionCobranzaItem>
          <Paga>N</Paga>
          <Permitido>S</Permitido>
          <Anio>2024</Anio>
          <Vencimiento>20/11/24</Vencimiento>
          <CodigoConcepto>200</CodigoConcepto>
          <Concepto>PATENTE</Concepto>
          <Cuota>6/6</Cuota>
          <Importe>1333.33</Importe>
          <Linea>1</Linea>
        </SDT_ColeccionCobranzaItem>
        <SDT_ColeccionCobranzaItem>
          <Paga>N</Paga>
          <Permitido>N</Permitido>
          <Anio/>
          <Vencimiento/>
          <CodigoConcepto>301</CodigoConcepto>
          <Concepto>ADELANTO DE CUOTAS PAT</Concepto>
          <Cuota/>
          <Importe>-133.33</Importe>
          <Linea>2</Linea>
        </SDT_ColeccionCobranzaItem>
      </Sdtcoleccioncobranza>
      <Auxiliarcobro>1046147</Auxiliarcobro>
      <Codigoretorno>000</Codigoretorno>
      <Mensajeretorno/>
    </GenWs03ConsultadeDeudaCC.ExecuteResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

```

---

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 18, 2023, 4:12pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/5 "2023-05-18T16:12:02Z")

</div>

I have already read it and that is exactly what I want to do, checking the value inside this tag:  
` <Buenpaga>S</Buenpaga>`

---

<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:** [May 18, 2023, 9:28pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/6 "2023-05-18T21:28:37Z")

</div>

Your XML has an element of which name contains a dot character (.)

> [@daimilamoru2018](#):
>
> \<GenWs03ConsultadeDeudaCC.ExecuteResponse

A dot character (.) is valid to be a part of XML Name. It is OK. The [spec](https://www.w3.org/TR/REC-xml/#charsets) allows it. But **ordinary people rarely use a dot in XML element name**. In this sence, your target XML is unusual.

On the other hand, the Katalon keyword uses a notation like [GPath](http://groovy-lang.org/processing-xml.html#_gpath). They named it as **locator**. The [documentation](https://docs.katalon.com/docs/create-tests/keywords/keyword-description-in-katalon-studio/web-service-keywords/ws-verify-element-text) gives an example of locator, like

```auto
'PreAuthorizeResponse.Receipt.TransactionResult'

```

You should note that **all dot characters ( . ) in a locator stands for the boundary of XML elements**. This locator correcponds to the target XML like:

```auto
<env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <ns:PreAuthorizeResponse xmlns:ns="beep" xmlns:ns2="bop" xmlns:ns1="foo" >
      <ns:Receipt>
        <ns1:DataKey>123</ns1:DataKey>
        <ns1:CustomerId>12345</ns1:CustomerId>
        <ns1:PaymentId>123456</ns1:PaymentId>
        <ns1:TransactionResult>Approved</ns1:TransactionResult>
...

```

Now, you should note that **the locator syntax implicitly assumes that the target XML document has NO elements that contain dot characters in the element name.**

* * *

Now let me review your case.

Your code

```auto
WS.verifyElementText(response, ‘GenWs03ConsultadeDeudaCC.ExecuteResponse.Buenpaga’, ‘S’)

```

This expects a XML element structure to be something like this:

```auto
...
<GenWs03ConsultadeDeudaCC>
    <ExecuteResponse>
        <Buenpaga>S</Buenpaga>
    ...

```

This structure is different from your target XML actually is. Therefore, Katalon’s keyword `WS.verifyElementText(response, locator, expectedValue)` can NEVER be correct against your target XML which uses a dot character (.) in the Name.

Any workaround? — You can not rely on WS.xxx keywords. So you need to write a tons of XML processing in Groovy. You would want to start learning the doc

[http://groovy-lang.org/processing-xml.html](http://groovy-lang.org/processing-xml.html)

and develop an art. You have to avoid the friendly “GPath” features. Possibly you would want to use [XPath 1.0](https://www.w3.org/TR/1999/REC-xpath-19991116/) paying enough attention to [XML Namespace](https://www.w3.org/TR/REC-xml-names/). I am afraid, this would be a difficult objective. I can not give you a quick and easy answer (as there is none).

My conclusion: Your target XML is unusual. It’s too difficult to process using WS.\* keywords. You had better abandun your objective in Katalon Studio.

---

<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:** [May 18, 2023, 10:00pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/7 "2023-05-18T22:00:57Z")

</div>

If your target XML is something like:

```auto
    <GenWs03ConsultadeDeudaCC_ExecuteResponse xmlns="GeoTribUy">
      <Buenpaga>S</Buenpaga>

```

Then the following code would work fine:

```auto
WS.verifyElementText(response, ‘GenWs03ConsultadeDeudaCC_ExecuteResponse.Buenpaga’, ‘S’)

```

Please note an underline ( \_ ) is used instead of a dot ( . ) in the element name.

But actually your case is different. It is not as easy as the assumed case unfortunately.

If possible, you should ask the developer(s) of the SOAP application to refrain from a dot character in XML Name as it makes many things difficult. I guess, they would be able to change a dot to an underbar with ease.

---

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 18, 2023, 11:23pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/8 "2023-05-18T23:23:40Z")

</div>

Thank you very much for your response. That xml is the one used in my work and it works fine, but in the automation it has brought me that problem I mentioned before.  
I will try to find a solution to this problem.

---

<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:** [May 19, 2023, 1:25am UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/9 "2023-05-19T01:25:54Z")

</div>

Let me show you my art of processing a XML document using the DOM & XPath API, which is runnable in Katalon Studio but uses none of Katalon’s features.

I saved the xml you presented above into a file `<projectDir>/response.xml` in a Katalon project.

I made a Test Case “TC1” like this:

```auto
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files

import javax.xml.namespace.NamespaceContext
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPath
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory

import org.w3c.dom.Document
import org.w3c.dom.NodeList

import com.kms.katalon.core.configuration.RunConfiguration

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path xml = projectDir.resolve("response.xml")
assert Files.exists(xml)

FileInputStream fileIS = new FileInputStream(xml.toFile())
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance()
builderFactory.setNamespaceAware(true)
DocumentBuilder builder = builderFactory.newDocumentBuilder()
Document xmlDocument = builder.parse(fileIS)

XPath xPath = XPathFactory.newInstance().newXPath()
xPath.setNamespaceContext(new NamespaceContext() {
	@Override
	public Iterator getPrefixes(String arg0) {
		return null;
	}
	@Override
	public String getPrefix(String arg0) {
		return null;
	}
	@Override
	public String getNamespaceURI(String arg0) {
		if ("my".equals(arg0)) {
			return "GeoTribUy"
		} else if ("SOAP-ENV".equals(arg0)) {
			return "http://schemas.xmlsoap.org/soap/envelope/"
		}
		return null
	}
})

String expr1 = "/SOAP-ENV:Envelope/SOAP-ENV:Body"
NodeList nodeList = (NodeList) xPath.compile(expr1).evaluate(xmlDocument, XPathConstants.NODESET)
println "nodeList.getLength()=" + nodeList.getLength()
assert nodeList.getLength() > 0

String expr2 = "/SOAP-ENV:Envelope/SOAP-ENV:Body/my:GenWs03ConsultadeDeudaCC.ExecuteResponse/my:Buenpaga";
String s = (String) xPath.compile(expr2).evaluate(xmlDocument, XPathConstants.STRING);
println s
assert s == "S"

```

I ran it and got the following output in the console:

```auto
2023-05-19 10:23:39.032 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2023-05-19 10:23:39.036 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/TC1
2023-05-19 10:23:40.565 DEBUG testcase.TC1 - 1: projectDir = Paths.get(getProjectDir())
2023-05-19 10:23:40.580 DEBUG testcase.TC1 - 2: xml = projectDir.resolve("response.xml")
2023-05-19 10:23:40.599 DEBUG testcase.TC1 - 3: assert Files.exists(xml)
2023-05-19 10:23:40.637 DEBUG testcase.TC1 - 4: fileIS = new java.io.FileInputStream(xml.toFile())
2023-05-19 10:23:40.682 DEBUG testcase.TC1 - 5: builderFactory = DocumentBuilderFactory.newInstance()
2023-05-19 10:23:40.708 DEBUG testcase.TC1 - 6: builderFactory.setNamespaceAware(true)
2023-05-19 10:23:40.727 DEBUG testcase.TC1 - 7: builder = builderFactory.newDocumentBuilder()
2023-05-19 10:23:40.773 DEBUG testcase.TC1 - 8: xmlDocument = builder.parse(fileIS)
2023-05-19 10:23:40.837 DEBUG testcase.TC1 - 9: xPath = newInstance().newXPath()
2023-05-19 10:23:40.858 DEBUG testcase.TC1 - 10: xPath.setNamespaceContext(new Script1684456048423$1(this))
2023-05-19 10:23:40.876 DEBUG testcase.TC1 - 11: expr1 = "/SOAP-ENV:Envelope/SOAP-ENV:Body"
2023-05-19 10:23:40.887 DEBUG testcase.TC1 - 12: nodeList = compile(expr1).evaluate(xmlDocument, NODESET)
2023-05-19 10:23:40.981 DEBUG testcase.TC1 - 13: println("nodeList.getLength()=" + nodeList.getLength())
nodeList.getLength()=1
2023-05-19 10:23:41.028 DEBUG testcase.TC1 - 14: assert nodeList.getLength() > 0
2023-05-19 10:23:41.032 DEBUG testcase.TC1 - 15: expr2 = "/SOAP-ENV:Envelope/SOAP-ENV:Body/my:GenWs03ConsultadeDeudaCC.ExecuteResponse/my:Buenpaga"
2023-05-19 10:23:41.034 DEBUG testcase.TC1 - 16: s = compile(expr2).evaluate(xmlDocument, STRING)
2023-05-19 10:23:41.085 DEBUG testcase.TC1 - 17: println(s)
S
2023-05-19 10:23:41.094 DEBUG testcase.TC1 - 18: assert s == "S"
2023-05-19 10:23:41.147 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/TC1

```

I could get access to the element and asserted its content text being “S”.

---

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 19, 2023, 1:50am UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/10 "2023-05-19T01:50:00Z")

</div>

I appreciate your time in helping me. So it looks like I will have to do a lot of coding to automate the checks on that xml. I don’t know why they did it this way

---

<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:** [May 19, 2023, 1:55am UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/11 "2023-05-19T01:55:49Z")

</div>

> [@daimilamoru2018](#):
>
> So it looks like I will have to do a lot of coding

Yes. Quite a lot to do.

> [@daimilamoru2018](#):
>
> why they did it this way

This is given. All you could do is to embrace it.

Or, if you could change the dot character ( . ) to an uderbar ( \_ ), then things will be far easier.

---

<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:** [May 19, 2023, 2:44am UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/12 "2023-05-19T02:44:15Z")

</div>

You can find the source code of Katalon Studio published at GitHub.

I could find the source of `WS.verifyElementText()` keyword and misc helpers. One of them is `WebServiceCommonHelper#parseAndExecuteExpressionForXml(String locator, ...)` at LINE#94

> <https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/webservice/helper/WebServiceCommonHelper.java>

```auto
public static Object parseAndExecuteExpressionForXml(String locator, String groovyFunction, String xmlText){
		String[] tokens = locator.split("\\.");
        ...

```

This code will parse the given locator string

`GenWs03ConsultadeDeudaCC.ExecuteResponse.Buenpaga`

into an array of String:

```auto
["GenWs03ConsultadeDeudaCC", "ExecuteResponse", "Buenpaga"]

```

This array is no longer relevant to the structure of the target XML document. So, the `WS.verifyElementText` keyword is not applicable to the XML document which @daimilamoru2018 wants to verify.

* * *

> [@daimilamoru2018](#):
>
> I appreciate your time in helping me.

I wrote those posts to this issue because I think that the Webservice features of Katalon Studio is carelessly designed, poorly implemented. You shouldn’t waste your time trying it.

---

<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:** [May 19, 2023, 3:06am UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/13 "2023-05-19T03:06:45Z")

</div>

I had a look at the document of Postman

> **[Using Postman to test SOAP web services | Reflect](https://reflect.run/articles/using-postman-to-test-soap-web-services/)**
>
> Learn how to use Postman to create automated API tests for SOAP web services

I found a sample code that verifies a SOAP response:

```auto
pm.test("InvertStringCase: AbCdE gets inverted to aBcDe", () => {
  // Convert XML to JSON

  var jsonObject = xml2Json(responseBody);

  // Move through the JSON tree to find the object that contains the inverted cased string

  var numberToWord = jsonObject["soap:Envelope"]["soap:Body"]["m:InvertStringCaseResponse"]["m:InvertStringCaseResult"];

  // Return a boolean where True means the test passed and False means the test failed

  return numberToWord == "aBcDe";
});

```

I guess, the Javascript code would work even if the target XML has an element of which name contains a dot character. Possibly @daimilamoru2018 would be able to write:

```auto
  var s = jsonObject["soap:Envelope"]["soap:Body"]["GenWs03ConsultadeDeudaCC.ExecuteResponse"]["Buenpaga"];

```

A dot character in XML element name would not hurt you in Postman.

---

<div class="post-metadata">

**Author:** ![daimilamoru2018](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daimilamoru2018/32/20464_2.png) [@daimilamoru2018](https://forum.katalon.com/u/daimilamoru2018)\
**Post date:** [May 19, 2023, 5:41pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/14 "2023-05-19T17:41:07Z")

</div>

Thank you so much again. If you have any private contact, please share it with me in order to discuss with more details.

---

<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:** [May 19, 2023, 11:24pm UTC](https://forum.katalon.com/t/ws-verifyelementtext/88275/15 "2023-05-19T23:24:42Z")

</div>

> [@daimilamoru2018](#):
>
> If you have any private contact, please share it with me in order to discuss with more details.

No, I am not willing to exchange private messages. I prefer to make all my posts exposed public.
