Skip to content

Instantly share code, notes, and snippets.

@chrisjlee
Created February 11, 2014 20:10
Show Gist options
  • Save chrisjlee/8943103 to your computer and use it in GitHub Desktop.
Save chrisjlee/8943103 to your computer and use it in GitHub Desktop.
Selenium: Retrieve option items from select list - found via https://groups.google.com/forum/#!topic/selenium-users/KxHTqpCFyWY
@import java.util;
@import org.openqa.selenium.By;
@import org.openqa.selenium.WebDriver;
@import org.openqa.selenium.Keys;
driver.findElement(By.xpath("//select[@id='categoryId']")).sendKeys("Foo");
// For more info Please find the below code
WebElement droplist = driver.findElement(By.xpath("//select[@id='categoryId']"));
List<WebElement> options = droplist.findElements(By.tagName("option"));
System.out.println(options.size());
for(int i=0 ; i<options.size() ; i++)
{
//WebElement o= options.get(i);
System.out.println(options.get(i).getText()+ " ---- "+ options.get(i).getAttribute("value"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment