How to add system date or future date on ui pop up instead of key sequence

Ask general questions here.
gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

How to add system date or future date on ui pop up instead of key sequence

Post by gsb » Wed Apr 07, 2021 10:38 pm

Instead of key sequence how to use system date in DD/MM/YYYY format to pass for every scenario.
repo path for element

Testcase code when converted key sequence into code
public void Key_sequence_ApplicationDate(RepoItemInfo inputtagInfo)
{
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '04/07/2021' with focus on 'inputtagInfo'.", inputtagInfo);
inputtagInfo.FindAdapter<InputTag>().PressKeys("04/07/2021");
}

repo path of element

?/?/form[@id='undefined']/tag[2]/tag[@tagname='row']/div/tag[@tagname='dynamic-control']/tag[@tagname='ng-component']/div/div/div/input[@id='applicationDate']

locked code
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '04/07/2021' with focus on 'FairwayBrokerPortal.ModalBodyTextCenter1.ApplicationDate'.", repo.testurlPortal.ModalBodyTextCenter1.ApplicationDateInfo, new RecordItemIndex(49));
repo.userportalPortal.ModalBodyTextCenter1.ApplicationDate.PressKeys("04/07/2021");
Delay.Milliseconds(0);

And how to get immediate response or online support for licensed users ? We have two currently Floating
Last edited by gsb on Thu Jun 17, 2021 10:12 pm, edited 1 time in total.

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Wed Apr 07, 2021 11:24 pm

Hi,

If I understand correctly you are looking to auto fill you date selection use system time. To do this we will write a simple coded action to place today's date in the correct format using the code below.


public void GetTime()
{
System.DateTime dt = System.DateTime.Today;
string date = String.Format("{0:MM/dd/yyyy}", dt);

repo.TestWebApplicatio.datefield.PressKeys(date);

}

Hope this helps!

Cheers,
Mike

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Thu Apr 08, 2021 12:11 am

yes Mike you understand it correctly

Since my test only works on today date

If you please also tell me where to write this code have shared everything here..

oh got it !! need to Map the user code with newly created GetTime() function ?

seems it works (added.jpg file)

Thanks

BTW what does this code do ?
string date = String.Format("{0:MM/dd/yyyy}", dt)
You do not have the required permissions to view the files attached to this post.

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Thu Apr 08, 2021 12:36 am

Hi there,

My apologizes for not explaining this very well but I am glad to hear you were able to easily decipher what I was trying to say :)

This code is taking the System.Date value and converting to the format we need and then saves it to a String data type which is what Ranorex needs.

//Create a variable to hold today's date
System.DateTime dt = System.DateTime.Today;

//Format the date variable in MM/dd/yyyy format and save it to a String variable.
string date = String.Format("{0:MM/dd/yyyy}", dt);

Hope this helps!

Cheers,
Mike

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Thu Apr 08, 2021 9:37 pm

Np Prob Bro, Many Thanks for explaining . Thank you

Just another query how add particular date in same code Like previous and current employment Start and End date

public void Empdate()
{
System.DateTime dt = System.DateTime.Today;
string date = String.Format("{0:MM/dd/yyyy}", dt);

repo.TestWebApplicatio.datefield.PressKeys(date);

}

Thanks Mike :)

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Mike K » Fri Apr 09, 2021 1:14 am

Something like this will give you previous date or future date

System.DateTime dt = System.DateTime.Today-7; //This would give you last week

System.DateTime dt = System.DateTime.Today+7; //Will give you next week

It is really up to you to determine how you want to calculate past and future dates.

Cheers,
Mike

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Mon Apr 12, 2021 4:19 pm

Thanks. Mike :)

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Mon Jun 14, 2021 8:04 pm

Hi @Support team :)

With extended date code am getting Error
System.DateTime dt = System.DateTime.Today+7;
Operator '+' cannot be applied to operands of type 'DateTime' and 'int' (CS0019)

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Mon Jun 14, 2021 9:31 pm

No Error with Adddays
System.DateTime.Today.AddDays(7);

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: How to add system date on ui pop up instead of key sequence

Post by Stub » Tue Jun 15, 2021 9:36 am

That's a coding error against the .NET Framework - you'll want to consult the MSDN documentation on that API to find out how to use it correctly.

gsb
Posts: 23
Joined: Wed Mar 17, 2021 3:49 pm

Re: How to add system date on ui pop up instead of key sequence

Post by gsb » Thu Jun 17, 2021 10:05 pm

@Support team @stub All Geeks
System.DateTime.Today.AddDays(7);
This also gives me today's date. Not adding next 15 Days

Code: Select all

System.DateTime fdt = System.DateTime.Today.AddDays(15);
	string date = String.Format("{0:MM/dd/yyyy}", fdt);

dragonvid
Posts: 1
Joined: Mon Sep 20, 2021 8:32 am

Re: How to add system date or future date on ui pop up instead of key sequence

Post by dragonvid » Mon Sep 20, 2021 9:21 am

i was also searching for the same thing