如何在 python selenium datepicker 中输入日期时间值?

How to enter datetime values in python selenium datepicker?

我有输入日期时间的页面,我有字符串形式的日期时间值,我将它传递给 find_element_by_xpath,我收到错误 这是我的 xpath

我在字符串变量中有值

value = '1980-06-30T00:00:00Z'

我用代码

xpath = '//*[@id="main-panel"]/div/app-manual-update/div/div/form/div[36]/div/input'
driver.find_element_by_xpath(xpath).send_keys(value);

我明白了

ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=94.0.4606.61)

HTML

如何传递日期时间值?

你需要使用 JS,如下所示:

from datetime import datetime
today_date = datetime.today().strftime('%Y-%m-%d')

wait = WebDriverWait(driver, 30)
date= wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id="main-panel"]/div/app-manual-update/div/div/form/div[36]/div/input")))
driver.execute_script(f"arguments[0].setAttribute('value', '2021-06-30T00:00:00Z')", date)

进口:

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

日期格式是yyyy-mm-dd也不要点击日期选择器,它会直接输入中的 输入字段。

在这里,您也可以使用arguments[0].value来设置属性值。

HTML:

代码:

date = wd.find_element_by_id("dobundefined")
driver.execute_script("arguments[0].value = '1980-06-30T00:00:00Z';", date)