I have Select Dropdown list with this:
xpath //*[@id="ddlTablePay"]
I need to count the number of options in this drop-down. Thank You
I have Select Dropdown list with this:
xpath //*[@id="ddlTablePay"]
I need to count the number of options in this drop-down. Thank You
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();
optionItems = Select(driver.find_element_by_xpath("//select[@id='ddlTablePay']"))
print "Total Elements " + str(len(optionItems.options))
//To count the number of options
Select dropDown = new Select(driver.findElement(By.id("ddlTablePay")));
List<WebElement> elementCount = dropDown.getOptions();
System.out.println("Number of items: " + elementCount.size());
//To get and print all the Options
Select dropDown = new Select(driver.findElement(By.id("ddlTablePay")));
List <WebElement> elementCount = dropDown.getOptions();
int itemSize = elementCount.size();
for(int i = 0; i < itemSize ; i++){
String optionsValue = elementCount.get(i).getText();
System.out.println(optionsValue);
}
Select selection= new Select(driver.findElement(By.id("Drop down id")));
int size=selection.getOptions().size();