hanzgs
hanzgs

Reputation: 1616

How to enter datetime values in python selenium datepicker?

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?

Upvotes: 3

Views: 3566

Answers (2)

Nandan A
Nandan A

Reputation: 2922

Here, you can use arguments[0].value also to set attribute value.

HTML:

enter image description here

Code:

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

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

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.

Upvotes: 1

Related Questions