3

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for that, It ran without error, but value not passed to the inputbox
I need to see the HTML, is page url public ?
I think I've got it, see that app-datetimepicker that has a value attribute You need to follow that pattern. like 2021-06-30T00:00:00Z
try this driver.execute_script("arguments[0].setAttribute('value', '2021-06-30T00:00:00Z')", date)
yeah that worked
|
1

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) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.