How to count the number of options in a select drop down box in Selenium WebDriver using Java? How to count the number of options in a select drop down box in Selenium WebDriver using Java? selenium selenium

How to count the number of options in a select drop down box in Selenium WebDriver using Java?


Use .getOptions() method and store them in a list .Then find its size.

Select se = new Select(driver.findElement(By.id("select drop down locator")));List<WebElement> l = se.getOptions();l.size();

-Ajay


String[] options = driver.findElement(By.id("dropdown")).getText().split("\n");options.length;


Use .getXpathCount() method

int numOptions = selenium.getXpathCount("//*[@id='ddlTablePay']/option").intValue();