Watch my below blog for complete ordered list of Selenium WebDriver topis:
http://seleniumwebdrivervideos.blogsp...
In this video i demonstrated about how to verify a value exists in the listbox.
Please find the below code which i used in demonstration:
WebDriver driver = new FirefoxDriver();
String strSearch="BMW X3555";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("file:///E:/Programming%20Samples/HTML%20Samples/DropDownListBox.html");
WebElement lbCars=driver.findElement(By.id("sampleListBox"));
Select select=new Select(lbCars);
List<WebElement> elements=select.getOptions();
boolean found=false;
for(WebElement ele:elements)
{
if(strSearch.equals(ele.getText()))
{
found=true;
break;
}
}
if(found)
System.out.println("Car model "+strSearch+" exists");
else
System.out.println("Car model "+strSearch+" does notexists");
driver.close();