# Count the number of elements in lists

**URL:** <https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062>\
**Category:** Miscellaneous\
**Created:** [August 3, 2017, 11:21pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062 "2017-08-03T23:21:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayah\_Nafie](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Ayah\_Nafie](https://forum.katalon.com/u/Ayah_Nafie)\
**Post date:** [August 3, 2017, 11:21pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/1 "2017-08-03T23:21:41Z")

</div>

Dear Support team,

I would like to know how can I count the number of list items (li) in a certain div.

(attached screenshot shows the html of the elements).

Get Number of total Option, doesn’t work since it requires a select field.

---

<div class="post-metadata">

**Author:** ![Ayah\_Nafie](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Ayah\_Nafie](https://forum.katalon.com/u/Ayah_Nafie)\
**Post date:** [August 3, 2017, 11:21pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/2 "2017-08-03T23:21:41Z")

</div>

Dear Support team,

I would like to know how can I count the number of list items (li) in a certain div.

(attached screenshot shows the html of the elements).

Get Number of total Option, doesn’t work since it requires a select field.

---

<div class="post-metadata">

**Author:** ![Oliver\_Howard](https://avatars.discourse-cdn.com/v4/letter/o/22d042/32.png) [@Oliver\_Howard](https://forum.katalon.com/u/Oliver_Howard)\
**Post date:** [August 4, 2017, 9:50am UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/3 "2017-08-04T09:50:42Z")

</div>

Hi there,

Please try the following solution where list.size() will be number of elements in this list

WebElement tem = driver.findElement(By.classname(“trip-cards”))  
List list = temp.findElement(By.xpath(".//li"))  
list.size()

Thanks

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Thank you for choosing Katalon Studio as your automation solution.  
Your feedback is needed to make Katalon Studio a better tool, take the survey at: [https://goo.gl/S25NVO](https://goo.gl/S25NVO)

---

<div class="post-metadata">

**Author:** ![Ayah\_Nafie](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Ayah\_Nafie](https://forum.katalon.com/u/Ayah_Nafie)\
**Post date:** [August 6, 2017, 5:13pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/4 "2017-08-06T17:13:33Z")

</div>

This didn’t solve the problem. The driver.findElement is not Katalon syntax and when I tried  
WebElement tem= WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/Page\_Gazef/Page\_Gazef/Trips/Search results/ul\_trip-cards’), 20)

I got the same exception of:

[ERROR] - Test Cases/Trips/Search page (Compare top 2 labels) FAILED because (of) org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “ul”  
Build info: version: ‘2.53.0’, revision: ‘35ae25b’, time: ‘2016-03-15 17:00:58’  
System info: host: ‘Ayah-Nafie-Mac.local’, ip: ‘10.13.2.73’, os.name: ‘Mac OS X’, os.arch: ‘x86\_64’, os.version: ‘10.11.6’, java.version: ‘1.8.0\_102’  
Driver info: driver.version: unknown

---

<div class="post-metadata">

**Author:** ![Oliver\_Howard](https://avatars.discourse-cdn.com/v4/letter/o/22d042/32.png) [@Oliver\_Howard](https://forum.katalon.com/u/Oliver_Howard)\
**Post date:** [August 6, 2017, 9:41pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/5 "2017-08-06T21:41:32Z")

</div>

Hi there,

Ah sorry my bad. You need to retrieve driver from DriverFactory class. My original script will look like this after adjustment

import org.openqa.selenium.By as By  
import org.openqa.selenium.WebDriver as WebDriver  
import org.openqa.selenium.WebElement as WebElement  
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

WebDriver driver = DriverFactory.getWebDriver()  
WebElement temp = driver.findElement(By.className(‘trip-cards’))  
List list = temp.findElement(By.xpath(’.//li’))  
list.size()

Please use this instead.

Thanks

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Thank you for choosing Katalon Studio as your automation solution.  
Your feedback is needed to make Katalon Studio a better tool, take the survey at: [https://goo.gl/S25NVO](https://goo.gl/S25NVO)

---

<div class="post-metadata">

**Author:** ![Ayah\_Nafie](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Ayah\_Nafie](https://forum.katalon.com/u/Ayah_Nafie)\
**Post date:** [August 8, 2017, 6:18pm UTC](https://forum.katalon.com/t/count-the-number-of-elements-in-lists/9062/6 "2017-08-08T18:18:54Z")

</div>

It worked at last 🙂 Thanks
