如何与 Selenium 中的 Ant Design 日历进行交互?

How to interact with Ant Design calendar from Selenium?

我有一个应用程序使用来自 Ant Design 的日历。

日期选择器似乎是只读属性。我需要在 Python.

中与 Selenium 中的这个元素进行交互

为了解决这个问题,我尝试了以下代码:

self.driver.execute_script("document.querySelector('.ant-calendar-picker-input.ant-input').readOnly = false")
self.driver.execute_script("document.querySelector('.ant-calendar-picker-input.ant-input').value ='12-12-2021'")
self.driver.execute_script("document.querySelector('.ant-calendar-picker-input.ant-input').readOnly = true")

使用此代码,日期不会更新(它确实在 UI 上发生了变化,但日期 HTML 属性为空)。我做错了什么?

以下是 HTML 代码的屏幕截图: 日期更新后(手动):

谢谢

根据您分享的HTML,我会advise您使用下面的代码更新date picker field,您不需要click 在日期选择器中,只需 运行 下面的 JS 代码。

wait = WebDriverWait(driver, 20)
date_to_fill = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#codigo_fecha_vencimiento input.ant-calendar-picker-input.ant-input")))
driver.execute_script("arguments[0].setAttribute('value', '15-09-2021')", date_to_fill)

进口:

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