acooper
acooper

Reputation: 141

Button clicked but nothing happens on webpage(Selenium WebDriver)

I am trying to click to "Get Data" button on this website. https://www1.nseindia.com/products/content/derivatives/currency/archieve_cd.htm

Here's my code. I have solved some of the issues but clicking doesnt work with no error.

import time
from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.action_chains import ActionChains

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By


chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("user-data-dir=C:/Users/UserName/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(ChromeDriverManager().install())

url = "https://www1.nseindia.com/products/content/derivatives/currency/archieve_cd.htm"
driver.get(url)
 
driver.find_element_by_xpath("//select[@name='h_filetype']/option[text()='Daily Bhavcopy']").click()
driver.find_element_by_id("date").send_keys('05-01-2021')
time.sleep(2)

driver.find_element_by_id("date").send_keys(Keys.ESCAPE)
time.sleep(2)

element = driver.find_element_by_css_selector('[class="getdata-button"]').click()

After clicking the button a zip file link should appear.Which has to be clicked next.

How to click "Get Data" button? Thank you very much :)

Upvotes: 2

Views: 489

Answers (1)

bilakos
bilakos

Reputation: 145

url = "https://www1.nseindia.com/archives/cd/bhav/CD_Bhavcopy050121.zip"
driver.get(url)

You delete all the rest of the code that exists after this.

driver.find_element_by_xpath("//select[@name='h_filetype']/option[text()='Daily Bhavcopy']").click()
driver.find_element_by_id("date").send_keys('05-01-2021')
time.sleep(2)

driver.find_element_by_id("date").send_keys(Keys.ESCAPE)
time.sleep(2)

element = driver.find_element_by_css_selector('[class="getdata-button"]').click()

This is the code that you don't need.

And if you want to make it to Auto Download more data try to make a code that will generate the calendar days and place them here CD_Bhavcopy050121.zip

So when you will want to extract the data from 05/01/2019 you will have to change the part of the html to this CD_Bhavcopy050119.zip

Upvotes: 1

Related Questions