我试图输入我自己选择的日期,但我被点击禁用的日期选择器卡住了
如果我点击日期选择器,它会弹出并要求点击日期,即使一个月我也必须点击更多
我很困惑该怎么办。
URL
http://finra-markets.morningstar.com/BondCenter/TRACEMarketAggregateStats.jsp
到目前为止我的代码。
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)
这不起作用。。!
Af首先,您需要单击"上个月"按钮,直到显示必要的年份和月份。(在您的情况下,您需要2017年10月(。循环的代码可能看起来像这样:
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)
当你成功的时候。考虑用智能等待代替睡眠官方文档,回答了类似的问题