3

I'm trying to input of my own choice of date but i am stuck click disabled datepicker.
If i click on datepicker it pops up and ask to click on the date even for a month I have to click more.
I'm confused here what to do.

URL

http://finra-markets.morningstar.com/BondCenter/TRACEMarketAggregateStats.jsp

My code so far.

from selenium import webdriver
from time import sleep
driver = webdriver.Chrome('path') # No Path Problem just changed here
driver.get('http://finra-markets.morningstar.com/BondCenter/TRACEMarketAggregateStats.jsp')
sleep(6)
date = driver.find_element_by_class_name("date-btn")
date.click()
sleep(4)
selector = driver.find_element_by_css_selector('[val="2017-10-11"]')
selector.click()
sleep(5)

this is not working..!

Ashfaque Marfani
  • 345
  • 4
  • 22

1 Answers1

1

Af first, you need to click 'previous month' button until you have a necessary year and month displayed. (in your case you need October 2017). The code of the loop may look like this:

date = driver.find_element_by_class_name("date-btn")
date.click()
sleep(4)
#getting element representing previous month button
prev_month = driver.find_element_by_class_name("pm")
#starting a loop that will click prev_month button untill calendar for October 2017 is shown
  # use .text because getText() does not work here
while driver.find_element_by_class_name("titleCont").text != "Oct 2017"
  prev_month.click()
  #You can play around this sleep's value. or just remove it completely
  sleep(2)
#Calendar should now be opened on Oct 2017 so we can look for desired date '11 october 2017
selector = driver.find_element_by_css_selector('[val="2017-10-11"]')
selector.click()
sleep(5)

When you make it work. Consider replacing sleeps with smart waits official doc, similar question answered

Ashfaque Marfani
  • 345
  • 4
  • 22
Vladimir Efimov
  • 797
  • 5
  • 13