Select Dropdown values using Selenium Webdriver 3.8













package mypackage;

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

public class Dropdown {

 public static void main(String[] args) {
  // TODO Auto-generated method stub

  String exepath = "C:\\Users\\Amit\\Downloads\\geckodriver-v0.19.1-win64//geckodriver.exe";
  System.setProperty("webdriver.gecko.driver", exepath);
  
  WebDriver driver = new FirefoxDriver ();
  
  driver.get("https://www.facebook.com/");
  
  //it will select 4
  Select dropdown_day = new Select (driver.findElement(By.id("day")));
  dropdown_day.selectByIndex(4);
  
  //it will select May
  Select dropdown_month = new Select (driver.findElement(By.id("month")));
  dropdown_month.selectByVisibleText("May");
  
  //it will select 2012
  Select dropdown_year = new Select (driver.findElement(By.id("year")));
  dropdown_year.selectByValue("2012");
  
 }

}





0 comments:

Post a Comment