1

I am trying to retrieve data from nseindia.com( https://www1.nseindia.com/products/content/equities/indices/historical_index_data.htm). I am using google chrome driver. The issue is: I am able to change the index, time period, but the button click doesn't work from selenium. Interestingly, when i open a browser tab in the web driver and just enter the above address, the page doesn't load....maybe the button click has been disabled for automation, any way around? My code snippet is like this:

driver.get('https://www1.nseindia.com/products/content/equities/indices/historical_index_data.htm')
            timeout = 60
            for i in range(5):
                try:
                    element_present = ec.presence_of_element_located((By.ID, 'indexType'))
                    WebDriverWait(driver, timeout).until(element_present)
                    time.sleep(5)
                    driver.find_element_by_id("fromDate").send_keys(from_date.strftime('%d-%m-%Y'))
                    time.sleep(2)
                    driver.find_element_by_id("toDate").send_keys(date2.strftime('%d-%m-%Y'))
                    break
                except TimeoutException:
                    print("Timed out waiting for page to load")
                    if i == 4:
                        sys.exit(1)
                    continue
         
            for individualElements in indexes:
                try:  
          Select(driver.find_element_by_id("indexType")).select_by_value(individualElements)
                    time.sleep(5)
                    driver.find_element_by_xpath("//input[@src='/common/images/btn-get-data.gif']").click()

I gave sleep of 2 seconds in between setting dates, 5 seconds before pressing submit, but no improvement. I tried in firefox webdriver also, but with little help. Any idea, what might be going there and any workaround i might try?

Thanks and Regards, Sudip

SudipM
  • 416
  • 7
  • 14

0 Answers0