title: How to select a value from drop down menu in python selenium
body: <p>I am writing a python script which will call a webpage and will select an option from the drop down to download that file. To do this task, I am using <a href="https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo" rel="nofollow noreferrer">chropath</a>. It is a browser extension which can give you the relative xpath or id for any button or field on the webpage and using that we can call it from python selenium script.</p>
  <p><a href="https://i.stack.imgur.com/lR0ID.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lR0ID.jpg" alt="enter image description here" /></a></p>
  <p>Above image shows the drop down menu in which I have to select <code>2019</code> as year and the download the file. In the lower part of the image, you can see that I have used <code>chropath</code> to get the relative xpath of the drop down menu which is <code>//select[@id='rain']</code></p>
  <p>Below is the code I am using:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.common.by import By
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.support import expected_conditions as EC
  
  driver = webdriver.Firefox()
  driver.get(&quot;&lt;URL&gt;&quot;)
  
  driver.maximize_window()
  
  grbf = driver.find_element_by_xpath(&quot;//select[@id='rain']&quot;) 
  grbf.send_keys('2019')
  
  grbf_btn = (By.XPATH, &quot;//form[1]//input[1]&quot;)
  WebDriverWait(driver, 20).until(EC.element_to_be_clickable(grbf_btn)).click()
  </code></pre>
  <p>from the above code, you can see that I am using xpath to select the drop down <code>grbf = driver.find_element_by_xpath(&quot;//select[@id='rain']&quot;) </code> and then sending keys as <code>2019</code> i.e. <code>grbf.send_keys('2019')</code> and after that I am calling download button to download it. But for some reason, its always selecting year <code>1999</code> from the drop down. I am not able to understand what is wrong in this. Is this correct approach to solve this. Please help. Thanks</p>