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

can anyone here suggest a method to select an item from a dropdown menu, using the item's position in the list?

Say you have a normal dropdown menu to select the month of birth. (Example on this page:

Usually the exported code from the webdriver IDE will have selected the respective item by name. Yet i would be more handy to actually selected it by list position. Thereby an simple integer ranging 1-12 from a database could be used to select an element on the list. This being more elegant than selecting from a group of 12 strings (January, February, ...)

I welcome any input!

Thank you!


share|improve this question

I don't know what programming language you use, but in Java you can do something like that:

Select select = new Select(driver.findElement("select")));

Here is the Select class:

share|improve this answer

Using Watir you can select by index as follows:

browser.select_list(:id=> 'month_of_birth').option(:index=> 0).select

In this case we are selecting the first option at the top of the drop down list. Also if you want to count the number of options there are then you can do:


You can use name instead of id in both cases if that's what is preferred.

Hope this helps!

share|improve this answer
Although this works, the OP seemed to be specifically asking about Selenium and WebDriver. – Lyndon Vrooman Aug 3 '14 at 15:37
That's fair, I'm just suggesting an alternative. – Kieran Edwards Aug 3 '14 at 15:39

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.