Sunday, October 8, 2017

How to select a value from dropdown ?

 By using Select class we can do this. Select class having different methods to select the dropdown value.

  1. selectByIndex()
  2. selectByValue()
  3. selectByVisibleText()          
     Example:

       WebElement element= driver.findElement(By.xpath("xpath of city dropdown"));


 
      Select dropdownvalue = new Select(element);
      dropdownvalue.selectByIndex(1); // It will select the 2nd drop down value- Jaipur
      dropdownvalue.selectByValue("Jaipur");
      dropdownvalue.selectByVisibleText("Jaipur");

No comments:

Post a Comment