title: how to select element by value from dropdown with java & selenium?
body: <p>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 &amp; VisibleText Both didnt work also tried to list element and loop on them but didnt work either</p>
  
  <p><strong>Update:</strong>
  it gives me error: <code>org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “button”</code></p>
  
  <p>how can i select from button with list of elements ??</p>
  
  <p>here is the code:</p>
  
  <pre><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&lt;WebElement&gt; optionsD = select.getOptions();
  
      for (WebElement option : optionsD) {
           code = option.getAttribute("value");
          if (code == selection) {
              option.click();
              break;
          }       
  
      }
  }
  </code></pre>
  
  <p>Screenshot of html
  <img src="https://i.stack.imgur.com/cmXTn.png" alt="here is the html code"></p>