Calculate options in dropdown with scroll


Could you please clarify how properly work with dropdowns that has a scroll in FE?
All the items are not displayed in DOM.

How can I calculate all the items?
How to locate the item that is not initially shown in DOM?

Thank you in advance for your help!

1 Like


I found this is similar: Counting total number of options available in dropdown - #2 by kazurayam

You won’t be able to use the WebUI.getNumberOfTotalOption() as it expects a select tag, which you don’t have. You can still get the count of items that are listed in the DOM by:

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

def driver = DriverFactory.getWebDriver()
List<WebElement> optionList = driver.findElements(By.xpath('//div[@class="scrollable-content"]/div[contains(@class, "ng-option")]'));
yourCount = optionList.size();

Now you want to calculate all your items, then you might try another way. Notice that the id attribute (doesn’t matter if the id is static or dynamic) in the “ng-dropdown-panel…” is similar to those for all your options. My suggestion would be to go to the last drop-down option and get the id attribute and then get the count after the hyphen, like

idBasedCnt = WebUI.getAttribute("yourLastDropDownObject", "id")
WebUI.comment("we found ${idBasedCnt}")
temp = idBasedCnt.split('-')[1]
yourCount = (temp as int) + 1

Hope that works for you.

Edit: as @Russ_Thomas says below, because the id starts at zero, we have to add 1 to the number on the end of the list.

Please ensure state is active , using parent child relation also, we can capture these

Add 1 and it might :nerd_face:

@yakovlieva.olena Question I have is, why do you want the total number of options? For what reason is that number important? I’m assuming you want the total – when you say “calculate” it’s a bit vague what you intended.

I also noticed this:


An empty div styled to be 33K pixels in height with a class with the intriguing name “total-padding”. Probably just more ng bloat but still… I’m intrigued.

Thank you for your comment.
I need a total number of options in dropdown:

  1. to be able to compare it with the expected result (the list is dynamic)
  2. to be able check data for random option of full dropdown

I will let you know about the purpose of blank div with impressive height as soon as I will know.

Best regards.