Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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

marked as duplicate by Yamikuronue, Bruce McLeod Feb 18 '15 at 10:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new 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:… – Peter Masiar Aug 1 '14 at 21:54
up vote 0 down vote accepted

In watir, this can be accomplished in one line:

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

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
WebElement selectElement = driver.findElement("id"));
Select listBox = new Select(selectElement);
int size1 = listBox.getOptions().size();
share|improve this answer

try this,

Select s = new Select(driver.findElement("#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

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