am trying to select country code from dropdown where the elements has no index or ID i can only select by value, i tried using SelectByValue & VisibleText Both didnt work also tried to list element and loop on them but didnt work either
Update:
it gives me error: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “button”
how can i select from button with list of elements ??
here is the code:
public void selectInDropDownMenuCountryCode(final WebDriver driver, final By selector, final String selection) {
_wait.until(ExpectedConditions.visibilityOfElementLocated(selector));
final Select select = new Select(driver.findElement(selector));
//select.selectByVisibleText(selection);
//select.selectByValue(selection);
String code;
List<WebElement> optionsD = select.getOptions();
for (WebElement option : optionsD) {
code = option.getAttribute("value");
if (code == selection) {
option.click();
break;
}
}
}
Screenshot of html