Bhavesh Ghodasara Bhavesh Ghodasara - 7 months ago 58
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 import Select
from bs4 import BeautifulSoup

driver = webdriver.Chrome()
# Switch to new window opened
# Close the new window
# Switch back to original browser (first window)

el = driver.find_element_by_id('sbToggle_27562807')

It gives error :-

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


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")