Not able to select value - error "Select only works on <select> elements, not on <a>"
<p>I am trying to retrieve all possible year, model and make from [<a href="https://www.osram-americas.com/en-us/applications/automotive-lighting-systems/Pages/lrgmain.aspx]" rel="nofollow">https://www.osram-americas.com/en-us/applications/automotive-lighting-systems/Pages/lrgmain.aspx]</a></p>

<pre><code>from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup

driver = webdriver.Chrome()
driver.get("https://www.osram-americas.com/en-us/applications/automotive-lighting-systems/Pages/lrgmain.aspx")
# Switch to new window opened
driver.switch_to.window(driver.window_handles[-1])
# Close the new window
driver.close()
# Switch back to original browser (first window)
driver.switch_to.window(driver.window_handles[0])

el = driver.find_element_by_css_selector("div#fldYear a.sbToggle")
el.click()
select = Select(el)
select.select_by_visible_text("2016")
</code></pre>

<p>However if I try to select year 2016. It is giving error :
Select only works on <code>&lt;select&gt;</code> elements, not on <code>&lt;a&gt;</code></p>

<p>The problem with your current approach is that you are finding the <code>a</code> element and trying to use it as a <code>select</code> element. <a href="http://selenium-python.readthedocs.io/api.html#selenium.webdriver.support.select.Select" rel="nofollow"><code>Select</code> class</a> will only work with <code>select</code> elements.</p>

<p>Note that in this case, it's easier to get to the invisible <code>select</code> element and get the years from its options directly:</p>

<pre><code>options = [option.get_attribute("innerText") for option in driver.find_elements_by_css_selector("select#ddlYear option")[1:]]
print(options)
</code></pre>

<p>The <code>[1:]</code> slice here is to skip the very first <code>Select Year</code> element.</p>

<hr>

<p>Complete working code:</p>

<pre><code>from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver


driver = webdriver.Chrome("/usr/local/bin/chromedriver")
driver.get("https://www.osram-americas.com/en-us/applications/automotive-lighting-systems/Pages/lrgmain.aspx")

wait = WebDriverWait(driver, 10)
toggle = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#fldYear a.sbToggle")))
toggle.click()

options = [option.get_attribute("innerText") for option in driver.find_elements_by_css_selector("select#ddlYear option")[1:]]
print(options)
</code></pre>

<p>Prints:</p>

<pre><code>[u'2016', u'2015', u'2014', u'2013', u'2012', u'2011', u'2010', u'2009', u'2008', u'2007', u'2006', u'2005', u'2004', u'2003', u'2002', u'2001', u'2000', u'1999', u'1998', u'1997', u'1996', u'1995', u'1994', u'1993', u'1992', u'1991', u'1990', u'1989', u'1988', u'1987', u'1986', u'1985', u'1984', u'1983', u'1982', u'1981', u'1980', u'1979', u'1978', u'1977', u'1976', u'1975', u'1974', u'1973', u'1972', u'1971', u'1970', u'1969', u'1968', u'1967', u'1966', u'1965', u'1964', u'1963', u'1962', u'1961', u'1960', u'1959', u'1958', u'1957', u'1956', u'1955']
</code></pre>

python selenium web-scraping