To select Combo box :
List dd = driver.findElement(By.name("_sacat")).findElements(By.tagName("option"));
for (WebElement option : dd) {
System.out.println(option.getText());
if ("Consumer Electronics".equalsIgnoreCase(option.getText())){
option.click();
break;
}
To select visible text from option
public void selectByVisibleText() {
Select selectBox = new Select(driver.findElement(By
.cssSelector("select#id_contact")));
selectBox.selectByValue("Customer service");
}
To Select index from option
public void selectByIndex() {
Select selectBox = new Select(driver.findElement(By
.cssSelector("select#id_contact")));
selectBox.selectByIndex(2);
}
Select selectBox = new Select(driver.findElement(By
.cssSelector("select#id_contact")));
selectBox.selectByIndex(2);
}
To get all option from selected tag
public void getOptions() {
Select selectBox = new Select(driver.findElement(By
.cssSelector("select#id_contact")));
List<WebElement> selectOptions = selectBox.getOptions();
for (WebElement temp : selectOptions) {
System.out.println("getText" + temp.getText());
}
}