title: Select dropdown option via Selenium
body: <p><strong>Set-up</strong></p>
  
  <p>I'm trying to select a country from a WooCommerce drop-down menu.</p>
  
  <pre><code>&lt;select name="shipping_country" id="shipping_country" class="country_to_state country_select select2-hidden-accessible" autocomplete="country" tabindex="-1" aria-hidden="true" style=""&gt;
      &lt;option value=""&gt;Selecteer een land…&lt;/option&gt;
      &lt;option value="BE"&gt;België&lt;/option&gt;
      &lt;option value="DE"&gt;Duitsland&lt;/option&gt;
      &lt;option value="FI"&gt;Finland&lt;/option&gt;
      &lt;option value="FR"&gt;Frankrijk&lt;/option&gt;
      &lt;option value="HU"&gt;Hongarije&lt;/option&gt;
      &lt;option value="NL" selected="selected"&gt;Nederland&lt;/option&gt;
      &lt;option value="AT"&gt;Oostenrijk&lt;/option&gt;
      &lt;option value="PL"&gt;Polen&lt;/option&gt;
      &lt;option value="ES"&gt;Spanje&lt;/option&gt;
      &lt;option value="GB"&gt;Verenigd Koninkrijk (UK)&lt;/option&gt;
  &lt;/select&gt; 
  </code></pre>
  
  <p>I've tried my usual way using <code>Select()</code> and have experimented with <code>ActionChains</code>, but to no avail. </p>
  
  <hr>
  
  <p><strong>Tries</strong></p>
  
  <ul>
  <li>Select 1</li>
  </ul>
  
  <p><code>Select(el_id('shipping_country')).select_by_value(latest_order['shipping']['country'])</code></p>
  
  <p>where <code>el_id() = browser.find_element_by_id()</code> and <code>latest_order['shipping']['country']</code> contains the 2 letter country code of shipping. </p>
  
  <p>This gives <code>ElementNotInteractableException: Element &lt;option&gt; could not be scrolled into view</code>.</p>
  
  <ul>
  <li>Select 2</li>
  </ul>
  
  <p>I've also tried to insert a 'wait',</p>
  
  <pre><code>dropdown = Select(el_id('shipping_country'))
  wait.until(EC.element_to_be_clickable((
          By.XPATH, "//select[@id='shipping_country']//options[contains(.," + latest_order['shipping']['country'] +")]")))
  dropdown.select_by_value(latest_order['shipping']['country'])
  </code></pre>
  
  <p>where <code>wait = WebDriverWait(browser, 10)</code>. </p>
  
  <p>This gives <code>TimeoutException</code>.</p>
  
  <ul>
  <li>ActionChains</li>
  </ul>
  
  <p>Based on an <a href="https://stackoverflow.com/a/31061941/7326714">answer</a>,</p>
  
  <pre><code>dropdown = el_xp("//select[@name='shipping_country']")
  actions = ActionChains(browser)
  actions.move_to_element(dropdown)
  actions.click(dropdown)
  select_box = Select(dropdown)
  actions.move_to_element(select_box.select_by_value(latest_order['shipping']['country']))
  </code></pre>
  
  <p>This gives, </p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-43-a82c544929aa&gt;", line 1, in &lt;module&gt;
      actions.move_to_element(select_box.select_by_value(latest_order['shipping']['country']))
  
    File "/Applications/anaconda/lib/python3.6/site-packages/selenium/webdriver/common/action_chains.py", line 289, in move_to_element
      self.w3c_actions.pointer_action.move_to(to_element)
  
    File "/Applications/anaconda/lib/python3.6/site-packages/selenium/webdriver/common/actions/pointer_actions.py", line 42, in move_to
      raise AttributeError("move_to requires a WebElement")
  
  AttributeError: move_to requires a WebElement
  </code></pre>
  
  <p><strong>How do I solve this?</strong></p>