Here is the code to get all the horse names from the website which requires three chars to populate the list of horse names
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome()
driver.get("https://www.indiarace.com/Home/horseStatistics/")
wait = WebDriverWait(driver, 10)
select_element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.form-control.search_header.js-data-example-ajax')))
horse_names = set()
for letter1 in range(ord('a'), ord('z') + 1):
for letter2 in range(ord('a'), ord('z') + 1):
for letter3 in range(ord('a'), ord('z') + 1):
search_query = f"{chr(letter1)}{chr(letter2)}{chr(letter3)}"
select_element.send_keys(search_query)
time.sleep(2)
options = select_element.find_elements_by_tag_name('option')
for option in options:
horse_names.add(option.text)
for name in horse_names:
print(name)
driver.quit()
The problem is your select_element
line. You're grabbing the SELECT element that is not visible... and it's not the right element for searching anyway. Selenium was designed to emulate an actual user and an actual user can't interact with an invisible element... that's why you are getting the "element not interactable" message.
You need to get the search INPUT to put in your search terms.
search = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "form.home-search-horse input.select2-search__field")))
search.send_keys(search_query)
That will populate HTML that looks like a dropdown but is not the SELECT. You can scrape your horse names from there. From what I can tell, the SELECT doesn't come into play until you actually choose one or more horses to search... then the SELECT gets populated with the chosen horse names.