我想点击日历的某一天(不管哪一天(如果可用
有些日子是可用的,有些则不是。
日历是用table
标签制作的,每个td
标签,如果不可用,都有一个类notSelectableDay
。
我必须重新加载页面,直到程序找到具有类selectableDay
的可用日期。
程序结构在我提出的另一个问题中,如果 else 在 Python 上循环。使用硒检查类名
这能行吗:
if driver.find_elements_by_class_name("selectableDay"):
driver.find_element_by_class_name("selectableDay").click()
我提出了另一个问题,解释得更清楚:
我有一个日历采摘器。如何使用Selenium和Python选择可用的日期?
代码,您可以在其中从日历中选择所需的日期。只需要传递要从日历中选择的日期即可。
from selenium import webdriver
def datepicker(date):
driverInstance = webdriver.Chrome()
driverInstance.get("http://www.seleniumframework.com/Practiceform/")
driverInstance.maximize_window()
driverInstance.find_element_by_id("vfb-8").click()
elements = driverInstance.find_elements_by_xpath(".//*[@id='ui-datepicker-div']/table/tbody/tr/td/a")
for dates in elements:
if(dates.is_enabled() and dates.is_displayed() and str(dates.get_attribute("innerText")) == date):
dates.click()
如果要从日历中选择日期 10,则将字符串"10"传递给函数
示例:datepicker("10")
如果您有任何问题,请告诉我。
elementos = driver.find_elements_by_class_name("calendarCellOpen")
while True:
if elementos:
driver.find_element_by_class_name("calendarCellOpen").click()
driver.find_element_by_id("ctl00_ContentPlaceHolder1_acc_Calendario1_repFasce_ctl01_btnConferma").click() #Confirm button
else:
driver.find_element_by_xpath("//input[@value='>']").click() #Forward the calendar
driver.find_element_by_xpath("//input[@value='<']").click() #Back the calendar
if elementos:
driver.find_element_by_class_name("calendarCellOpen").click()
driver.find_element_by_id("ctl00_ContentPlaceHolder1_acc_Calendario1_repFasce_ctl01_btnConferma").click() #Confirm button
也许这可以工作..而不是find_element xpath,但我认为无论如何它都会起作用。