select value in list WebDriver

Select value in weblist using WebDriver

The below example open spicejet.com and select Goa in from list


FirefoxDriver fd=new FirefoxDriver();
fd.get("http://www.spicejet.com");
Thread.sleep(5000);

WebElement ListBox = fd.findElement(By.id("from1Select"));
List options = ListBox.findElements(By.tagName("option"));
for(WebElement option : options)
{
 if(option.getText().equals("Goa"))
 {
    option.click();
    break;
 }
}


Aslo it works like this

fd.findElement(By.xpath("//select[@id='from1Select']/option[@value='Goa'"]")).click();

Comments