# Automated date field

**URL:** <https://forum.katalon.com/t/automated-date-field/55622>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [June 10, 2021, 10:15am UTC](https://forum.katalon.com/t/automated-date-field/55622 "2021-06-10T10:15:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferrariklersone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ferrariklersone/32/15706_2.png) [@ferrariklersone](https://forum.katalon.com/u/ferrariklersone)\
**Post date:** [June 10, 2021, 10:15am UTC](https://forum.katalon.com/t/automated-date-field/55622/1 "2021-06-10T10:15:55Z")

</div>

Hello people,  
please the date field can’t be filled in with text, how to automate in this case?

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/5/e/5e0150892ba05c37468f0ea90e0d10813f233cd7.png)

thank you for help!

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [June 10, 2021, 3:34pm UTC](https://forum.katalon.com/t/automated-date-field/55622/2 "2021-06-10T15:34:46Z")

</div>

The first thing to do is to right click on the date GUI and review the HTML. Then it depends if you can select a **static** date, or current date (i.e. just click on the “Today” link), or if you need to input a specific date ( **dynamic** ).

> **Maybe try**
>
> I created two objects based on the HTML of OUR Calendar GUI: select\_DatePickerMonth and select\_DatePickerYear. For these two objects, I used a simple xpath for each–again, review **your** HTML.  
> select\_DatePickerMonth  
> `//select[@class="ui-datepicker-month" and @data-handler="selectMonth"]`
> 
> select\_DatePickerYear  
> `//select[@class="ui-datepicker-year" and @data-handler="selectYear"]`
> 
> ```auto
> "click on date input field"
> WebUI.click(findTestObject('myPage/input_ADate'))
> 
> Date todaysDate = new Date()
> dayPart = todaysDate[Calendar.DAY_OF_MONTH]
> monthPart = todaysDate[Calendar.MONTH]
> yearPart = todaysDate[Calendar.YEAR] 
> 
> "set the month"
> WebUI.waitForElementClickable(findTestObject('myPage/select_DatePickerMonth'), 10)
> "get the VALUE of this element"
> WebUI.selectOptionByValue(findTestObject('myPage/select_DatePickerMonth'), monthPart.toString(), false)
> 
> "set the year"
> WebUI.waitForElementClickable(findTestObject('myPage/select_DatePickerYear'), 10)
> "get the LABEL of this element"
> WebUI.selectOptionByLabel(findTestObject('myPage/select_DatePickerYear'), yearPart.toString(), false)
> 
> "set the day"
> WebElement selCalendarTable = driver.findElement(By.xpath('//table[@class="ui-datepicker-calendar"]/tbody'))
> 
> List<WebElement> Rows = selCalendarTable.findElements(By.tagName('tr'))
> 
> Loop:
> for (int i = 0; i < Rows.size(); i++) {
> 
> 'To locate columns(cells) of that specific row'
> List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))
> 
> for (int j = 0; j < Cols.size(); j++) {
> 
> if (Cols.get(j).getText().equals(dayPart.toString())) {
> WebUI.comment("found day ${dayPart}" )
> Cols[j].click();
> break Loop;
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![ferrariklersone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ferrariklersone/32/15706_2.png) [@ferrariklersone](https://forum.katalon.com/u/ferrariklersone)\
**Post date:** [June 11, 2021, 8:45am UTC](https://forum.katalon.com/t/automated-date-field/55622/4 "2021-06-11T08:45:41Z")

</div>

@grylion54  
So with spy web function, i captured **Today** button and use it in my test case, step is ok.

but if i need to input a specific date, that’s my problem now.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [June 11, 2021, 3:12pm UTC](https://forum.katalon.com/t/automated-date-field/55622/5 "2021-06-11T15:12:12Z")

</div>

Perhaps, you can set up your date using String functions. Something like below:

```auto
strDate = "15/06/2017" // 15th of June, 2017

dayPart = Integer.parseInt(strDate.split('/')[0]) 
monthPart = Integer.parseInt(strDate.split('/')[1]) - 1
yearPart = Integer.parseInt(strDate.split('/')[2])

```

and then similarly to my thought bubble above, to select your “month”:

```auto
"get the VALUE of this element"
WebUI.selectOptionByValue(findTestObject('myPage/select_DatePickerMonth'), monthPart.toString(), false)

```

If you do it based on getting the date by parsing using the Calendar statics, like “Calendar.MONTH”, then you do **not** need to minus 1. This is because the Calendar statics are zero based, whereas we start January as month one. ‘01/01/2021’

---

<div class="post-metadata">

**Author:** ![ferrariklersone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ferrariklersone/32/15706_2.png) [@ferrariklersone](https://forum.katalon.com/u/ferrariklersone)\
**Post date:** [June 11, 2021, 3:19pm UTC](https://forum.katalon.com/t/automated-date-field/55622/6 "2021-06-11T15:19:36Z")

</div>

Thank you dear, i will try to code it.
