Unable to set date & time correctly in the date field & time field respectively

Hi, I have added data below in my internal test data:
Date = 11/03/2021
Time = 06 : 30

But when running in chrome & firefox browser, both are showing different data.
For example:
date become 01/01/2100 & for time, it is changing the minute only


I have tried the following methods, but it is not working in both browsers

WebUI.focus(findTestObject(‘object’))
WebUI.executeJavaScript(‘$(':input').removeAttr('readonly')’, )
WebUI.delay(1)
WebUI.setText(findTestObject(‘object’), DeceasedDate)
WebUI.sendKeys(findTestObject(‘object’), DeceasedDate)

Do anyone have solution for this?

A quick look and it seems you are setting the Deceased Date to both the date and time, however, you only indicate object so maybe it is only the date field you are trying to set. If you are only setting the date field, then I wouldn’t setText and sendKeys with the same reference. How about something like setText the date and sendKeys a Tab, like below. Do you set your Date to a String? And set the Time as a String also.

import org.openqa.selenium.By as By
import org.openqa.selenium.Key as Key
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement

Date todaysDate = new Date();
def DeceasedDate = todaysDate.format("MM/dd/yyyy");
def DeceasedTime = "06:30";

WebUI.setText(findTestObject('my Page/input_DeathDate'), DeceasedDate)
WebUI.sendKeys(findTestObject('my Page/input_DeathDate'), Keys.chord(Keys.TAB))
WebUI.click(findTestObject('my Page/textArea_NewbornAbnomolies'))
WebUI.verifyElementAttributeValue(findTestObject('my Page/input_DeathDate'), 'value', DeceasedDate, 10)

WebUI.setText(findTestObject('my Page/input_DeathTime'), DeceasedTime)
WebUI.sendKeys(findTestObject('my Page/input_DeathTime'), Keys.chord(Keys.TAB))
WebUI.click(findTestObject('my Page/textArea_NewbornAbnomolies'))
WebUI.verifyElementAttributeValue(findTestObject('my Page/input_DeathTime'), 'value', DeceasedTime, 10)

If you have a calendar GUI that appears when you enter the date, then I would add a click on the “Newborn Abnomalies” after doing the sendKeys. You may even want to put in a WebUI.delay(1) after the click statement as well.

Or another way
import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement

WebDriver driver = DriverFactory.getWebDriver();
Date todaysDate = new Date();
def DeceasedDate = todaysDate.format("MM/dd/yyyy");
def DeceasedTime = "06:30";

pItem = driver.findElement(By.id('inputdeathDate'));
pItem.sendKeys(DeceasedDate);

WebUI.verifyMatch(pItem.getAttribute("value"), DeceasedDate, false)

pItem2 = driver.findElement(By.id('inputdeathTime'));
pItem2.sendKeys(DeceasedTime);

WebUI.verifyMatch(pItem2.getAttribute("value"), DeceasedTime, false)

In this case you should try to set values to: inputdeathTime or deathTime for time value as you can see in the locator for time value in the screenshot. Then you have to check the locator for the date as we can see only time locators .

Maybe you can provide to us your locator for “date” only being highlighted on the dom as well

There are two images in the question above. The first image is the deathDate and the second image is for the deathTime.

deathDate or inputdeathDate was missing , sorry . You are right