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


In watir, this can be accomplished in one line:

browser.select_list(:id=> 'id').options.count

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"));


WebElement selectElement = driver.findElement(By.id("id"));
Select listBox = new Select(selectElement);
int size1 = listBox.getOptions().size();

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.

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