While trying to get chromedriver in selenium to select a date in the calendar, I’m stuck with a hidden field for the date.
I’ve used the following code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
url = "https://www.fpi.nsdl.co.in/web/Reports/Archive.aspx"
date_value = '2024-06-04'
driver = webdriver.Chrome()
driver.get(url)
try:
date_button = driver.find_element(By.XPATH, '//*[@id="hdnDate"]')
driver.execute_script("arguments[0].removeAttribute('type')", date_button)
uh_date_button = driver.find_element(By.XPATH, '//*[@id="hdnDate"]')
driver.execute_script("arguments[0].setAttribute('value', arguments[1])", uh_date_button, date_value)
date_button.click()
# Click on the "view report" button
view_report_button = driver.find_element(By.XPATH, '/html/body/form/div[3]/div[2]/div[4]/table/tbody/tr[1]/td[3]/a[1]/div[2]')
view_report_button.click()
# Click on the "export to excel" button
export_button = driver.find_element(By.XPATH, '/html/body/form/div[3]/div[2]/div[4]/table/tbody/tr[1]/td[3]/a[2]/div[2]')
export_button.click()
except TimeoutException:
print("Timed out waiting for page elements to load")
finally:
driver.close()
driver.quit()
It gets stuck in calendar and doesn’t do anything
I expected to be able to select a date on calendar and populate the page. My non working code is given above
New contributor
aardbark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.