Automated date field

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


thank you for help!

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[@class="ui-datepicker-month" and @data-handler="selectMonth"]

//select[@class="ui-datepicker-year" and @data-handler="selectYear"]

"click on date input field"'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'))

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}" )
			break Loop;

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.

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

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”:

"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’

Thank you dear, i will try to code it.