Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

working on selenium + java,. can any one help me... I have a drop down list box, and need to get the number of elements in the list box.

<select id="id">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

need to get the count, ie, 3..... thanks and in advance

share|improve this question
What you tried so far? Did google gave you any suggestions? –  Peter Masiar Aug 1 '14 at 13:34
5 seconds of googling (java+ selenium + title of your question) resulted in this: stackoverflow.com/questions/20210853/… –  Peter Masiar Aug 1 '14 at 21:54

3 Answers 3

Try this , storing all the Web elements of Select list in a List and then getting its size.

List<WebElement> optionCount = driver.findElements(By.xpath("//select/option"));


share|improve this answer

try this,

Select s = new Select(driver.findElement(By.id("#id")));
List<WebElement> list = s.getOptions();

There you have all the elements of your dropdown, and using the size() method you'll have all the options.

share|improve this answer

In watir, this can be accomplished in one line:

browser.select_list(:id=> 'id').options.count
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.