ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to select a value from a dropdown ?

We can select a value from a dropdown by using WebDriver’s Select class.

Syntax:

  1. selectByValue:
  2. Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
  3. selectByValue.selectByValue(“greenvalue”);
  4.  
  5. selectByVisibleText:
  6. Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
  7. selectByVisibleText.selectByVisibleText(“Lime”);
  8.  
  9. selectByIndex:
  10. Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
  11. selectByIndex.selectByIndex(2);
  1. public Select(WebElement element)

A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
Parameters:element – SELECT element to wrapThrows:UnexpectedTagNameException – when element is not a SELECT

Facebook Comments

Check Your Domain Ranking

Leave a Reply

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

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!