Dropdown

DROP DOWN:    Select dropdownMonth = new Select(dropdown);

public class SampleStable {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver",
                "E:\\selenium\\SeleniumStable\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.facebook.com");
        WebElement dropdown = driver.findElement(By.id("month"));
        dropdown.sendKeys("Jan");
        Select dropdownMonth = new Select(dropdown);
        dropdownMonth.selectByIndex(12);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Select dropdownDay = new Select(driver.findElement(By.id("day")));
        dropdownDay.selectByValue("12");

        Select dropdownYear = new Select(driver.findElement(By.id("year")));
        dropdownYear.selectByVisibleText("1988");
        driver.quit();  }}

Alternate to Dropdown list:

public class DropDownList {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver",
                "E:\\selenium\\SeleniumStable\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.facebook.com");
        WebElement element= driver.findElement(By.id("month"));
        List<WebElement>dropdown= element.findElements(By.tagName("option"));
        System.out.println(dropdown.size());
      
        for(int i=1 ;i<=dropdown.size()-1;i++)
        {
            System.out.println(dropdown.get(i).getText());
          
          }
    }

}

Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium