# Trying to Use getElementsCount Keyword

**URL:** <https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [February 20, 2020, 3:37pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136 "2020-02-20T15:37:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamela.wittman](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@pamela.wittman](https://forum.katalon.com/u/pamela.wittman)\
**Post date:** [February 20, 2020, 3:37pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/1 "2020-02-20T15:37:16Z")

</div>

When calling an API the response consists of a collection of Transactions. Each collection consists of 4 elements (Balance, Transaction Date, Type, and Amount)

[  
{  
“balance”: “404.01”,  
“transactionDate”: “2020-02-19”,  
“type”: “WITHDRAWAL”,  
“amount”: “-40”  
},  
{  
“balance”: “444.01”,  
“transactionDate”: “2020-02-19”,  
“type”: “WITHDRAWAL”,  
“amount”: “-55.99”  
}  
]

Using JSONPathFinder I can see that each collection is assigned a “position”, for example the first is set consists of [0].balance, [0].transactionDate, [0].type, and [0].amount

I need to loop thru the returned response collection and then verify each element in each set.  
I attempted to use the Web services keyword of getElementCount to determine the outer loop count but got an error on the call after I set it up

def slurper = new groovy.json.JsonSlurper()  
def responseObj = slurper.parseText(requestObj.getResponseBodyContent())

**TransCount = WS.getElementsCount(responseObj, null)**

This is the error received

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.getElementsCount() is applicable for argument types: (java.util.ArrayList, null) values: [[[amount:-40, balance:404.01, transactionDate:2020-02-19, type:WITHDRAWAL], …], …]  
Possible solutions: getElementsCount(com.kms.katalon.core.testobject.ResponseObject, java.lang.String), getElementsCount(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, com.kms.katalon.core.model.FailureHandling)

There doesn’t seem to be any Help info on this call that I could find…has anyone successfully used this in setting up a loop?

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [February 20, 2020, 6:10pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/2 "2020-02-20T18:10:53Z")

</div>

Hi @pamela.wittman,  
The first parameter of getElementsCount must be a ResponseObject instance. And the second one is a string that describes your locator. We are sorry that the docs has not been updated with guidance for this keyword. However, you can refer to the doc of keyword verifyElementsCount, with similar parameters, to know the meaning and what value to define for each parameter ([https://docs.katalon.com/katalon-studio/docs/ws-verify-elements-count.html#description](https://docs.katalon.com/katalon-studio/docs/ws-verify-elements-count.html#description))

---

<div class="post-metadata">

**Author:** ![pamela.wittman](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@pamela.wittman](https://forum.katalon.com/u/pamela.wittman)\
**Post date:** [February 20, 2020, 6:56pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/3 "2020-02-20T18:56:15Z")

</div>

thanks for the info. my 1st param is the response object but the API does not show a “locator” in the returned response - it is returned EXACTLY as shown below, so what can be used in this scenario? I tried “null” but that did not work…

[  
{  
“balance”: “404.01”,  
“transactionDate”: “2020-02-19”,  
“type”: “WITHDRAWAL”,  
“amount”: “-40”  
},  
{  
“balance”: “444.01”,  
“transactionDate”: “2020-02-19”,  
“type”: “WITHDRAWAL”,  
“amount”: “-55.99”  
},  
{  
“balance”: “500”,  
“transactionDate”: “2020-02-19”,  
“type”: “DEPOSIT”,  
“amount”: “500”  
}  
]

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [February 22, 2020, 4:36pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/4 "2020-02-22T16:36:00Z")

</div>

Hi @pamela.wittman,  
Try passing an empty string ("") as your locator.

---

<div class="post-metadata">

**Author:** ![anon46315158](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon46315158](https://forum.katalon.com/u/anon46315158)\
**Post date:** [February 23, 2020, 10:50am UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/5 "2020-02-23T10:50:06Z")

</div>

> [@pamela.wittman](#):
>
> def responseObj = slurper.parseText(requestObj.getResponseBodyContent())

this will return an ‘array’ of objects (in fact a list)

so, `responseObj.size()` should give you the number of objects, no need for locators.

---

<div class="post-metadata">

**Author:** ![zaraaq9](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/zaraaq9/32/16103_2.png) [@zaraaq9](https://forum.katalon.com/u/zaraaq9)\
**Post date:** [January 6, 2021, 9:27pm UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/6 "2021-01-06T21:27:04Z")

</div>

Did anyone get an answer for this? There’s not much online about getElementsCount() method.

Thanks

---

<div class="post-metadata">

**Author:** ![anon46315158](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon46315158](https://forum.katalon.com/u/anon46315158)\
**Post date:** [January 7, 2021, 8:14am UTC](https://forum.katalon.com/t/trying-to-use-getelementscount-keyword/40136/7 "2021-01-07T08:14:03Z")

</div>

> [@zaraaq9](#):
>
> There’s not much online about getElementsCount() method.

You can check the Javadoc at:

[https://docs.katalon.com/javadoc/com/kms/katalon/core/webservice/keyword/builtin/GetElementsCountKeyword.html](https://docs.katalon.com/javadoc/com/kms/katalon/core/webservice/keyword/builtin/GetElementsCountKeyword.html)

So, this keyword it is similar with VerifyElementCount in usage (as already mentioned), you have to provide and response object and an locator in the method signature (and optional an FailureHandling constant).  
This keyword will return an integer.

For VerifyElementCount you have to provide in addition an expected value and will return a boolean.
