title: How to select an option from a dropdown through Selenium WebDriver
body: <p>I have the following <em>Inspected element Id</em> for a dropdown with a few fields in a UI screen.</p>
  
  <p><strong>DropDown values:</strong></p>
  
  <ul>
  <li>List item1</li>
  <li>List item2</li>
  <li>List item3</li>
  </ul>
  
  <p><strong>Inspected Element ID:</strong></p>
  
  <pre><code>&lt;select id="form1:PartialSysAdminKey_adminContractIdField" name="form1:PartialSysAdminKey_adminContractIdField" class="selectOneMenu" size="1"&gt;
  </code></pre>
  
  <p>There will be cases when the drop down will hold no values.</p>
  
  <p>I need to display a sysout log, only when this drop down has atleast one value.</p>
  
  <p>Can someone please suggest how can I incorporate this in my Selenium testing?</p>
  
  <p>Currently, I have this following code that checks whether the server is up and tests a login.</p>
  
  <pre><code>package testPackage;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.chrome.ChromeOptions;
  
  public class TestClass {
  
      public static void main(String[] args) {
  
          ChromeOptions options = new ChromeOptions();
          options.addArguments("headless");
  
          System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chromedriver_win32\\chromedriver.exe");
  
          WebDriver driver = new ChromeDriver();
          driver.get("https://bigdata/steward.jsp");
  
          if (driver.getTitle().equalsIgnoreCase("Login")) {
                  serverStatus = "UP";
          } else {
              serverStatus = "DOWN";
          }
          System.out.println("Server is " + serverStatus + ".");
  
          if (serverStatus.equalsIgnoreCase("UP")) {
              driver.findElement(By.id("username")).sendKeys("username");
              driver.findElement(By.id("password")).sendKeys("password");
              driver.findElement(By.id("login")).click();
  
              String newUrl = driver.getCurrentUrl();
  
              if (newUrl.equalsIgnoreCase("https://bigdata/error.jsp")) {
                  System.out.println("Incorrect username/password.");
              } else {
                  System.out.println("Logged in successfully.");
              }
          } else {
              System.out.println("Login could not be done.");
          }
          driver.quit();
      }
  }
  </code></pre>