Created
February 11, 2014 20:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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