Date is not being pasted correctly in the date input field

Hi everybody,

I trust that you are all well. I am new to Katalon studio and am currently experiencing an issue when adding a date to an input of type date. it is only pasting the date and excluding the month and the year

This is the screenshot of the input with the day pasted only excluding the month and year.
image

This is the date input test object screenshot

This is the screenshot of the script mode implementation in a test case

def dateOfBirth = new Date().parse('yyyy/mm/dd', '1994/10/23').format('yyyy/mm/dd')
WebUI.click(findTestObject('Page_Clientle/input_Member Date Of Birth 1'))
WebUI.delay(2)
WebUI.setText(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

I have tried everything that I have seen on the forums and nothing is working. Please help me out.

I am looking forward to your responses

1 Like

I don’t understand what you want to do. Please restate it in easier English.

I want date value (in the format yyyy-mm-dd) to be added/pasted correctly into the date input box. Currently, it is only adding/pasting part of the date e.g. yyyy/mm/23 instead of e.g. 2025/10/23

You once wrote that you want to “exclude the month and the year”. It would usually mean you want to convert a date string of “2025/10/23” into another string of “23”.

Now you wrote something different.

I am confused.

Could you explain what this error message means?

It seems to me that the web app want you to type only “23” but you typed “2025/10/23”, therefore the web app complained to you and advised you to type “23”. Am I right?

If I am not right, please describe how the web app wants you to do: type a “Date” string of “2025/10”? or “2025/10/23”? or “2025-10-23”?

I want the test case execution to paste 2025-10-23 when it runs but its currently only pasting “23” on the UI and this is incorrect. As a result of this, when the form is submitted, there is a validation error displayed as per the screenshot you provided. The date format is not an issue. I am using the correct format that is required i.e. yyyy-mm-dd or 2025-10-23

I managed to get it to work using the executeJavascript keyword below. However, I would like to it in a much cleaner way without using the executeJavascript keyword.

WebUI.executeJavaScript("document.getElementById('Input_DoBMember1').value = '1994-10-23'", null)

You posted the following code:

Please note that you specified .format('yyyy/mm/dd').

On the other hand, you wrote:

I think your code will NOT generate the “correct” format.

  1. ‘/’ or ‘-’ — which character do you really want?
  2. Java’s SimpleDateFormat requires M as month in the format string, but you gave m which will be interpreted to be minute for SimpleDateFormat

I would recommend you to study the following article:

Maybe even simpler, instead of converting a String DoB into a Date and back into a String, just input the String DoB into your field, like:

def dateOfBirth = '1994-10-23';

WebUI.verifyElementVisible(findTestObject('Page_Clientle/input_Member Date Of Birth 1'))

WebUI.click(findTestObject('Page_Clientle/input_Member Date Of Birth 1'))

WebUI.setText(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

WebUI.verifyElementAttributeValue(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), "value", dateOfBirth, 10)

Otherwise, @kazurayam is correct and you will have to change your Date format command to “yyyy-MM-dd” or “yyyy/MM/dd”, however you want it.

The issue occurs because the date format in your script doesn’t match the input[type="date"] field’s expected format (YYYY-MM-DD). Here’s the fix:


1. Correct the Date Format

Modify the date parsing/formatting to use dashes (-) instead of slashes (/):

groovy

def dateOfBirth = new Date().parse('yyyy/MM/dd', '1994/10/23').format('yyyy-MM-dd')
// Output: "1994-10-23"

Why This Works:

  • input[type="date"] requires YYYY-MM-DD format.
  • Use MM (month) instead of mm (minutes).

2. Use setValue Instead of setText

Katalon’s setValue method handles HTML5 date inputs more reliably:

groovy

WebUI.setValue(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

3. Full Fixed Script

groovy

// Parse and format date correctly
def dateOfBirth = new Date().parse('yyyy/MM/dd', '1994/10/23').format('yyyy-MM-dd')

// Click and set value
WebUI.click(findTestObject('Page_Clientle/input_Member Date Of Birth 1'))
WebUI.delay(2)
WebUI.setValue(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

4. Alternative: JavaScript Injection

If the above fails due to input masking/validation:

groovy

WebUI.executeJavaScript(
  "document.querySelector('input[name=\"memberDateOfBirth\"]').value = '1994-10-23'",
  null
)

Why Your Original Code Failed

  • Format Mismatch: Slashes (1994/10/23) vs. dashes (1994-10-23).
  • Incorrect Pattern: mm represents minutes, not months (use MM).

Verification Steps

  1. Manually test the date field in the browser with 1994-10-23.
  2. Check the element’s value attribute after execution:

groovy

String value = WebUI.getAttribute(findTestObject('input_Member Date Of Birth 1'), 'value')
assert value == '1994-10-23'

Troubleshooting

  • If the field uses a custom date picker, use WebUI.sendKeys with arrow keys.
  • For calendar pop-ups, interact with the UI elements directly instead of setting the value.

Example with SendKeys:

groovy

WebUI.sendKeys(findTestObject('input_Member Date Of Birth 1'), Keys.chord(Keys.CONTROL, 'a'))
WebUI.sendKeys(findTestObject('input_Member Date Of Birth 1'), '1994-10-23')

Firstly,
I cannot find the setValue() in the WebUiBuiltInKeywords import on Katalon studio. Does the setValue() exist on the free version of Katalon Studio?

Secondly,

When I use WebUI.executeJavascript()
e.g.

WebUI.executeJavaScript(
  "document.querySelector('input[name=\"memberDateOfBirth\"]').value = '1994-10-23'",
  null
)

Its currently not triggering the onChange. This is only working when I am manually testing. How can I go about correcting this?

No.

@dineshh replied:

Katalon’s setValue method handles HTML5 date inputs more reliably:

I believe that this is a fiction.

I wonder why @dineshh wrote such a fiction. I suppose @dineshh is not a human; he/she/it might be an AI agent that tends to generate fictions.

Which AI agent are you using for these answers?
I notice that ChatGPT frequently hallucinates Katalon keywords.
If you are using StudioAssist then perhaps this should be raised as a bug? Expectation would be that an in-house agent should be trained against the API specification - if some other agent, then user beware!

3 Likes

I looked at the doc of SmartAssist, and found it writes:

Known limitations

StudioAssist comes with some limitations:

  • Possible AI hallucinations: StudioAssist might generate code with made-up built-in keywords. You need to double-check the generated code and revise with the valid equivalent.

In case @dineshh uses SmartAssist, we should not raise a bug report concerning the WebUI.setValue keyword as it is a known limitation, not a bug.

And, as the doc advises us, we need to double-check the @dineshh’s posts in this forum as it seems that @dineshh never examines his/her/its codes on hand before posting.

1 Like

Have you tried either WebUI.setText() or WebUI.sendKeys() for entering your text as @dineshh suggests? Personally, go with these first for simplicity? And did either of them work?

def dateOfBirth = '1994-10-23';

WebUI.setText(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

or

WebUI.sendKeys(findTestObject('Page_Clientle/input_Member Date Of Birth 1'), dateOfBirth)

WebUI.verifyElementAttributeValue(findTestObject('Page_Clientle/input_Member Date Of Birth 1'),  'value', dateOfBirth, 10)

If you get a Calendar that appears after you enter the date, you may need to click on a label or some other field to have the Calendar disappear.

"date of birth"
WebUI.verifyElementVisible(findTestObject('myPage/input_Basic.DateOfBirth'))
WebUI.setText(findTestObject('myPage/input_Basic.DateOfBirth'), gBirthDate)
WebUI.click(findTestObject('myPage/input_Basic.MaidenName'))
WebUI.verifyElementAttributeValue(findTestObject('myPage/input_Basic.DateOfBirth'),
	"value", gBirthDate, 10)

Edit: If the Date did not place into the field, does the field have a Calendar icon that you can interact with? I have had to use this on one of my projects, so it is doable, but you have to treat the Calendar like a web-table.

1 Like