title: Selenium Drop Down Box
body: <p>I'm trying to automate account registration using Selenium java and I'm having troubles clicking a drop down menu on the registration. I want it to click the secret question drop down and select "Who is your favorite author?". Here is the html code.</p>
  
  <pre><code>&lt;div class="clear input_wrapper_bg"&gt;
      &lt;div class="name_field"&gt;
          &lt;label for="SecretQuestion"&gt;Secret Question&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="select_field"&gt;
          &lt;div class="select2-container" id="s2id_SecretQuestion"&gt;
              &lt;a href="#" onclick="return false;" class="select2-choice" tabindex="-1"&gt;&lt;span&gt;What is your mother's maiden name?&lt;/span&gt;&lt;abbr class="select2-search-choice-close" style="display:none;"&gt;&lt;/abbr&gt;
              &lt;div&gt;
                  &lt;b&gt;&lt;/b&gt;
              &lt;/div&gt;
              &lt;/a&gt;
              &lt;div class="select2-drop select2-with-searchbox select2-drop-active select2-offscreen" style="display: block;"&gt;
                  &lt;div class="select2-search"&gt;
                      &lt;input type="text" autocomplete="off" class="select2-input select2-focused"&gt;
                  &lt;/div&gt;
                  &lt;ul class="select2-results"&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;select data-val="true" data-val-required="The Secret Question field is required." id="SecretQuestion" name="SecretQuestion" style="display: none;"&gt;
              &lt;option value="What is your mother's maiden name?"&gt;What is your mother's maiden name?&lt;/option&gt;
              &lt;option value="What was your high school mascot?"&gt;What was your high school mascot?&lt;/option&gt;
              &lt;option value="Who is your favorite author?"&gt;Who is your favorite author?&lt;/option&gt;
              &lt;option value="What was the name of your first pet?"&gt;What was the name of your first pet?&lt;/option&gt;
          &lt;/select&gt;
          &lt;div class="error_msg"&gt;
              &lt;span class="field-validation-valid" data-valmsg-for="SecretQuestion" data-valmsg-replace="true"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have tried using </p>
  
  <pre><code> new Select(driver.findElement(By.id("s2id_SecretQuestion"))).selectByVisibleText("Who is your favorite author?");
  </code></pre>
  
  <p>But it doesn't work because when I click the drop down menu it adds some more html code at the bottom of the page.</p>
  
  <pre><code>&lt;div class="select2-drop select2-with-searchbox select2-drop-active" style="display: block; top: 541.109375px; left: 876.3125px; width: 310px;"&gt;
      &lt;div class="select2-search"&gt;
          &lt;input type="text" autocomplete="off" class="select2-input select2-focused" tabindex="-1"&gt;
      &lt;/div&gt;
      &lt;ul class="select2-results"&gt;
          &lt;li class="select2-results-dept-0 select2-result select2-result-selectable"&gt;
          &lt;div class="select2-result-label"&gt;
              &lt;span class="select2-match"&gt;&lt;/span&gt;What is your mother's maiden name?
          &lt;/div&gt;
          &lt;/li&gt;
          &lt;li class="select2-results-dept-0 select2-result select2-result-selectable"&gt;
          &lt;div class="select2-result-label"&gt;
              &lt;span class="select2-match"&gt;&lt;/span&gt;What was your high school mascot?
          &lt;/div&gt;
          &lt;/li&gt;
          &lt;li class="select2-results-dept-0 select2-result select2-result-selectable"&gt;
          &lt;div class="select2-result-label"&gt;
              &lt;span class="select2-match"&gt;&lt;/span&gt;Who is your favorite author?
          &lt;/div&gt;
          &lt;/li&gt;
          &lt;li class="select2-results-dept-0 select2-result select2-result-selectable select2-highlighted"&gt;
          &lt;div class="select2-result-label"&gt;
              &lt;span class="select2-match"&gt;&lt;/span&gt;What was the name of your first pet?
          &lt;/div&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Any help would be appreciated. Thanks.</p>