Hi,
Here i want to select options in 'search' drop down one after one.Means if i selected 'Books' option and click then
again it should go and click on another option like 'Music' .
Please refer my below code:
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.findElement(By.cssSelector("#searchDropdownBox")).click();
driver.findElement(By.cssSelector("#searchDropdownBox > option:nth-child(2)")).click();
String valueToSelect= null;
WebElement select = driver.findElement(By.cssSelector("#searchDropdownBox"));
Select dropDown = new Select(select);
String selected = dropDown.getFirstSelectedOption().getText();
List<WebElement> Options = dropDown.getOptions();
for(WebElement option:Options){
if(option.getText().equals(valueToSelect)){
if(selected.equals("books"))
option.isSelected();
}
if(selected.equals("music"))
option.isSelected();
}}
}