Bhavesh Ghodasara Bhavesh Ghodasara - 2 months ago 14
Python Question

Unable to click invisible select python

I am trying to retrieve all possible lists from this website

Model will only open when year is selected. Similarly Make will only open when Model is selected. I want to store all combination of Year, Model and Make for learning purpose.

However I am not able to click year field only. It seems it is hidden and without this I can't go ahead with rest of 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_id('sbToggle_27562807')
el.click()


It gives error :-


Message: no such element: Unable to locate element: {"method":"id","selector":"sbToggle_27562807"}

Answer

Message: no such element: Unable to locate element: {"method":"id","selector":"sbToggle_27562807"}

year element is not hidden, actually your locator to locate element using find_element_by_id('sbToggle_27562807') is not correct. In this element id attribute value is dynamically changing that's why you're unable to locate this element.

Instead of id locator you should try using some different locator. I would suggest, for better way try using find_element_by_css_selector() as below :-

el = driver.find_element_by_css_selector("div#fldYear a.sbToggle")
el.click()