Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium在禁用的日期选择器上输入日期_Python_Python 3.x_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python Selenium在禁用的日期选择器上输入日期

Python Selenium在禁用的日期选择器上输入日期,python,python-3.x,selenium,selenium-webdriver,selenium-chromedriver,Python,Python 3.x,Selenium,Selenium Webdriver,Selenium Chromedriver,我试图输入我自己选择的日期,但我被卡住了,无法点击日期选择器 如果我点击datepicker,它会弹出并要求点击日期,即使是一个月,我也必须点击更多。我不知道该怎么办 网址 我的代码到目前为止 from selenium import webdriver from time import sleep driver = webdriver.Chrome('path') # No Path Problem just changed here driver.get('http://finra-mark

我试图输入我自己选择的日期,但我被卡住了,无法点击日期选择器
如果我点击datepicker,它会弹出并要求点击日期,即使是一个月,我也必须点击更多。
我不知道该怎么办

网址

我的代码到目前为止

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)

当你成功的时候。考虑用明智的等待代替睡眠,

谢谢。在得到webelement error后,我做了一些编辑来运行它。太棒了!谢谢你的编辑。我的错。。。我不使用phyton,所以有点猜测。
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)