title: find top value dynamically from drop down menu using selenium python
body: <p>I'm using Python with Selenium. I'm trying to automate an application in which i need to extract top value from a drop menu. The values keep on changing so i cannot pass a static xpath to my selenium python code.</p>
  
  <p>I tried the following code but none of them working.</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.chrome.options import Options
  from selenium.webdriver.support.ui import Select
  import selenium.webdriver.support.ui as UI
  select=driver.find_element_by_xpath("//*[@id='code' and @name='Code1']")
  for option in select.options:
      print(option.text,option.get_attribute('value'))
  </code></pre>
  
  <p>The idea is to find all the values and extract the top value. When i print <code>select.options</code> I don't see anything.
  I extracted the following HTML by inspecting the drop down menu.</p>
  
  <pre><code>&lt;select name="Code1" style="width:250px" class="code" id="code"&gt;
      &lt;option value="Select Code"&gt;Select  Code&lt;/option&gt;
      &lt;option value="GGGSGSG:C"&gt;GGGSGSG:C&lt;/option&gt;
      &lt;option value="AHR060"&gt;AHR060--NORTH&lt;/option&gt;
      &lt;option value="AGSGGS"&gt;AGSGGS--PTSTTS&lt;/option&gt;
      &lt;option value="NANNAN"&gt;NANNAN--BTSTT&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Now the values keep changing so I cannot pass any specific value in xpath. I need to find all option values dynamically and pass the top one to a variable and using that variable call xpath and click the element.</p>