首页 > 解决方案 > 具有多个月日期的python selenium中的日期选择器

问题描述

我对 Python selenium 有点陌生,我有一个程序需要选择回溯日期来获取数据。我经历了堆栈平台中已经提出的许多问题,我的日历如下所示。它在同一张表中也显示了上个月或下个月的日期,有人可以帮我查找有关此类日历的文档,它们被称为什么以及如何处理它们。我试图点击返回日期,代码没有给出错误,但它不起作用。

在此处输入图像描述

代码我试图点击所需的日期,但它根本不起作用:

prev=driver.find_element_by_xpath("//th[@class='previous'][1]")


while((cmonth)!=(target_month) and (cyear)!=(target_year) ):
    time.sleep(3)
    Show10=driver.find_element_by_xpath("//div[@class='datetimepicker']/table[1]/thead[1]/tr[1]/th[contains(text(),'previous')").click()
    Show10.click()
    month=driver.find_element_by_xpath("//span[@class='month']")
    cmonth=month.get_attribute("innerHTML")
    year=driver.find_element_by_xpath("//span[@class='year']")
    cyear=year.get_attribute("innerHTML")


day=driver.find_element_by_xpath("//div[@class='datetimepicker']//table[@class='days']//tbody")

for row in day.find_elements_by_xpath("//tr"):
    for cell in row.find_elements_by_xpath("td"):
        if (cell.text == expecteddate):
            req_date = driver.find_element_by_link_text(cell.text)
            req_date.click()
            break

标签: pythonseleniumdatepickerselenium-chromedriver

解决方案


推荐阅读