I was able to show the total count of the dropdown. But Now, I want to skip the heading value and show the remaining count of the drop-down. Is that even possible?

Hi guys
I have a query. I want to get the TOTAL count of the drop-down values but in the count, I want to skip the Heading part.
For Example:
DropDown
Value 1 = Project (Heading)
Value 2 = B
Value 3 = C

With the XPath, it will show the count of 3 but I want to show it as 2, excluding the Value 1. Is that possible?
Please see the Screenshots for further understanding:


This is my code: For now, it is showing The count with the heading part

//Get the total count of the Projects
		List<WebElement> elems = WebUiCommonHelper.findWebElements(Projects_Count_In_Same_Page_Global, 30)

		println ("Getting all the values: " + "\n" + elems.text  )
		println('No of Projects with the: ' +  ProjectName + " name are "+ elems.size())

and this is the Xpath for the drop-down

You have to show the selector used in your Test Object to get a proper help.

LE: nvm, I see you are trying it in DevTools. See the solution from @grylion54

Not an expert in WebUI but I suppose is currently matching by style='list-style-blah which will pick all of them.

You may have to change it to filter by class='hover:blah'

If there is always a heading then the count is always count - 1.

Otherwise, you will need to do it via the selector/locator, as @bionel suggested.

So is it the last 3 items that have class that you are trying to count?

//div[@class="col-md-3 col-xs-12"][1]/ul/li[contains(@class,"underline pointer")]

or to just get your heading:

//div[@class="col-md-3 col-xs-12"][1]/ul/li[not(@class)]

I was tempted to suggest the same, since is the most trivial for count.
But the user may later ask :i need to access element[idx]
Because, why not?
For this, idx may work, but is not a guarantee,no matter zero or one based index

Yes, only the last 3 lines have class so as the Heading part doesn’t have class I made some changings in my xPath!

This is the Xpath that I made
//li[@class=“hover:underline pointer ml-3”]

before I was accessing it through div so it was showing the data count with the heading. but now its showing the count without the HEADING Part :slight_smile: I just hope this approach is correct.

Thanks for your time @bionel @Russ_Thomas @grylion54