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.

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: http://www.plus2net.com/php_tutorial/date-selection.php)

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!

Mest

share|improve this question

1 Answer 1

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

Select select = new Select(driver.findElement(By.id("select")));
select.selectByIndex(1);

Here is the Select class: http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/Select.html

share|improve this answer

Your Answer

 
discard

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.