简体   繁体   English

为什么弹出的日历没有点击进入下个月(python,selenium)?

[英]Why does the pop-up calendar not click into the next month (python, selenium)?

I wrote a simple code below to open the reservation calendar and click to the following month, but the calendar doesn't seem to be switching to the next month.我在下面写了一个简单的代码,打开预订日历,点击到下个月,但日历似乎没有切换到下个月。 Is there something glaring that I am missing?有什么明显的东西我失踪了吗?

driver.get("https://www.tablecheck.com/shops/peterluger/reserve")
driver.maximize_window() 

driver.find_element_by_id("reservation_start_date").click()
driver.find_element(By.XPATH, "//div[@aria-label='Next Month']").click()

The outer HTML外部 HTML

<input class="form-control mobidate i-txt refresh-menu-items mbsc-comp" readonly="" placeholder="-- Select Date --" type="text" name="reservation[start_date]" id="reservation_start_date" value="2021-10-13">

shows that it has an value attribute in form of 2021-10-13 .显示它具有形式为2021-10-13的 value 属性。

We do not need to click on this input field and then select a value from the calendar .我们不需要单击input field然后select a value from the calendar

Instead we can directly pass the value attribute using execute script in Python-Selenium bindings .相反,我们可以使用Python-Selenium 绑定中的execute script直接pass the value attribute

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://www.tablecheck.com/shops/peterluger/reserve")
date = wait.until(EC.visibility_of_element_located((By.ID, "reservation_start_date")))
driver.execute_script("arguments[0].scrollIntoView(true);", date)
driver.execute_script("arguments[0].setAttribute('value', '2021-10-13')", date)

Imports :进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Before click the element, try to move first to the target.在单击元素之前,先尝试移动到目标。

Learn about ActionChains :了解ActionChains

driver.get("https://www.tablecheck.com/shops/peterluger/reserve")
driver.maximize_window() 

driver.find_element_by_id("reservation_start_date").click()

element = driver.find_element(By.XPATH, "//div[@aria-label='Next Month']")
action = ActionChains(driver)
action.move_to_element(element).click(element).perform()

Following import:以下导入:

from selenium.webdriver import ActionChains

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM