from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from random import randint
from time import sleep
# Path to chromedriver
chromedriver_path = "C:/0 Python Programmes/1 Python KD/1 DATA DOWNLOAD/2 NIFTY 500 OHLC DATA/3 DOWNLOAD FROM NSE/0 NSE OHLC VOL DELIVERY PCT CSV DOWNLOAD/chromedriver.exe"
# Set Chrome options to specify download directory and file type
chrome_options = Options()
chrome_options.add_experimental_option("prefs", {
"download.default_directory": r"C: Python Programmes2 Data20 Selenium1 NSE", # Change this path to your desired download directory
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
# Change the User-Agent string
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
chrome_options.add_argument(f"user-agent={user_agent}")
# Initialize the WebDriver with Chrome options
service = Service(chromedriver_path)
driver = webdriver.Chrome(service=service, options=chrome_options)
# Website to fetch data
website = "https://www.nseindia.com/report-detail/eq_security"
# Open the target website
driver.get(website)
# Wait for the dropdown element to be clickable
search_box_click = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#hsa-symbol")))
sleep(1)
search_box_click.click()
sleep(2)
search_box_click.clear()
sleep(1)
# locate the search box where name is to be typed letter wise
search_box = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#hsa-symbol")))
sleep(3)
search_box.send_keys("I")
sleep(1)
search_box.send_keys("T")
sleep(2)
search_box.send_keys("C")
sleep(1)
# Wait for the suggestion list to appear (increase the timeout if needed)
suggestion_list = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "hsa-symbol_listbox")))
print(suggestion_list.text)
output: ‘No record found’
but when I type this letter manually in this website a list of suggested optioned are available, though in rare case same programme show that options. please guide me
whenever any two letters of a symbol typed in this website, it automatically suggest some company name with symbol i want to automate this process so i try to perform same task through python but does not work.