How to add sys date to a date field

Hi,
I want to add sys date to a field (Not before date) and sysdate +5( nort after date) .
I have added the dates in excelsheet and i was able to add the dates successfully via data driven testing but i am told to add date not via excel sheet. So how i will add the dates to these fields.

Attributes for Not Before date
[@name = ‘pt1:contentAreaReg:0:tabrg1:2:notBeforeDate’ and @id = ‘pt1:contentAreaReg:0:tabrg1:2:notBeforeDate::content’]

Atttributes for Not After Date
[@name = ‘pt1:contentAreaReg:0:tabrg1:2:notBeforeDate’ and @id = ‘pt1:contentAreaReg:0:tabrg1:2:notBeforeDate::content’]

Could you please help on this

hi,

not really get your point, could you clarify a bit your needs

Hi Timo,
Thanks for your reply.
there are two dates fields in my application. 1. NOT after data and 2. Not Before date .
My reruirement is to pick sys date from calender. e.g . if date is 28-Mar-20 it will pick the date from the calnder ( i,.e from Not after date or NOt Before Date field).
Earlier I have added the dates in excelsheet and i was able to add the dates in the Not after date or NOt Before Date field successfully via data driven testing .
But i was told not to add this way.
Can you advise how to add the dates in these two fields.
hope you got my req.
Thanks!

hi,

not sure but check this site
https://mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/

Hi,
The below two fields are mentioned below.
I want to add the sysdate in these two fields.
image

hi,

are those fields read only true, mean you are not able to input any values to fields?
if yes then set field value as readOnly = false
WebUI.executeJavaScript("return document.getElementsByClassName('<class name>')[0].readOnly=false;", null)
after that you should be able to add value to field

this index [0] depends on how many with same class name your UI page have
e.g all those in view have same class name then “Not Before Date” index is [2] (start from 0)
and second field index is [3]

You can get the current system date as follows:

String format = "MM/dd/yyyy"
SimpleDateFormat sdf = new SimpleDateFormat(format)
String date = sdf.format(new Date())

Be sure to change the format to suit your needs.

Hi ,
i have added below coded and date 14-apr-2020 is selected in not before field and also date is selected to the not after field but after the date selected in not after field , the date is atomatically getting cleared in not after field, i do not know why this is happening.Can you please help me on this.

String format = 'MM/dd/yyyy'

SimpleDateFormat sdf = new SimpleDateFormat(format)

String date = sdf.format(new Date() + 4)

WebUI.sendKeys(findTestObject('Page_Create Order  Merchandising/input_pt1contentAreaReg0tabrg12notBeforeDate'), date)
WebUI.sendKeys(findTestObject('Page_Create Order  Merchandising/input_pt1contentAreaReg0tabrg12notAfterDate'), date)