Home > Enterprise >  How to enter datetime values in python selenium datepicker?
How to enter datetime values in python selenium datepicker?

Time:09-30

I have the page to enter datetime, I have the datetime value as string, I am passing that to through the find_element_by_xpath, I am getting error This is my xpath

enter image description here

I have the value in string variable

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

I use the code

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

I get

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

HTML ![enter image description here

How to pass the datetime value?

CodePudding user response:

You need to use JS, like below :

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)

Imports :

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

Date format is yyyy-mm-dd also make sure to not click on date picker, it will directly input the values in input field.

  • Related