Print all options of the dropdown using Selenium Webdriver

package webdriver;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class PrintAllfromDropDown {
	
	static WebDriver driver;

	public static void main(String[] args) {
		
		driver = new FirefoxDriver();
		
		driver.manage().window().maximize();
		
		driver.get("http://www.facebook.com");
		
		WebElement element = driver.findElement(By.id("month"));
		
        Select opt = new Select(element);        
        
        List<WebElement> allOptions = opt.getOptions();
        
        System.out.println("Total Options are --" +allOptions.size());
      
        for (int i=0; i<allOptions.size(); i++)
        {        	
            String optionValue = allOptions.get(i).getText();
            
            System.out.println(optionValue);
        }
		driver.quit();

	}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *