I trust that this information will be beneficial for you.
WebElement mainElement = driver.findElement(By.className("nav-search-scope nav-sprite"));
Select select = new Select(mainElement);
java.util.List <WebElement> optionsList = select.getOptions(); // retrieve all options from the drop down
int size = optionsList.size();
String [] buttonArray = new String[size];
for (int k = 0; k < size; k++) {
buttonArray[k] = optionsList.get(k).getText();
if(buttonArray[k] == "All"){
select.selectByVisibleText("All");
}
}
Alternatively, you can utilize the following method to choose the 'All' option:
public static void getDropdownAllOption(WebDriver driver, WebElement mainElement)
{
Select select = new Select(mainElement);
java.util.List <WebElement> optionsList = select.getOptions(); // grab all options from the drop down
int size = optionsList.size();
String [] buttonArray = new String[size];
for (int k = 0; k < size; k++) {
buttonArray[k] = optionsList.get(k).getText();
if(buttonArray[k] == "All"){
select.selectByVisibleText("All");
}
}
}
If you require selecting a drop down by visible text, you can implement the subsequent method:
public static void selectByVisible(WebElement mainElement, String selectedValue)
{
WebElement elementToSelect = mainElement;
Select dropdown = new Select(elementToSelect);
dropdown .selectByVisibleText(selectedValue);
}