Page 1 of 1

Validate date in dropdownlist

Posted: Thu Dec 17, 2015 4:28 am
by ViMac
How can I validate date that's input using 3 drop-down lists are day, month, year?
date-dropdownlist.png
Please kindly consider and advise. I'm looking forward to everyone reply.

Re: Validate date in dropdownlist

Posted: Thu Dec 17, 2015 8:42 am
by odklizec
Hi,

Please post a Ranorex snapshot of the element in question. Screenshot is unfortunately useless. Without snapshot, we can provide you only with some general suggestions.

What you have to do is to extract the day, month, year values from each dropdown. Then merge them to day/month/date string and then simply compare it with actual DateTime converted to String.

Eventually, you can convert the date string (obtained from dropdown) to DateTime structure and compare it with actual DateTime. You will also most probably have to format the obtained date to match the actual DateTime string (or vice versa).

So basically, you will have to write some C#/VB .Net code to do all this. The DateTime part alone should not be a big problem. There are plenty of DateTime examples found at this forum of webs like msdn, stackoverflow or dotnetperls. The question is, if you can obtain the day/month/year values from the dropdowns? Are you able to see these values if you track the dropdowns in question with Ranorex Spy?

Re: Validate date in dropdownlist

Posted: Thu Dec 17, 2015 9:07 am
by Martin
Hey

Plesae send a snapshot for the elements you need the validations for.

Guide here: http://www.ranorex.com/support/user-gui ... files.html

I can't actually see a way doing this without some usercode.

You will probably have to get the innerText value from the dropdowns selected element.
Then you would need a reference against what to validate. So probably implementing the
System.DateTime.Now.ToString("dd.MM.yyyy");

The month's in your dropdowns are probably in string format so you will have to convert the comparison month format to full month string format.

Then you can just see if the innerText for the active month element contains the month value.

Code: Select all

// Get todays date
string date = System.DateTime.Now.ToString("dd.MM.yyyy");

// Split elements
string[] dateSplit = date.Split('.');

// Create representitive int elements for the month, day and year and convert string

int day = Convert.ToInt32(dateSplit[0]);
int month = Convert.ToInt32(dateSplit[1]);
int year = Convert.ToInt32(dateSplit[2]);

// And finally get the string value from the month int
string monthName = new System.DateTime(year, month, day).ToString("MMMM", System.Globalization.CultureInfo.InvariantCulture);
So this is the code to get a comparision object. The monthName should be checked against the innerText from the active month element to see if the innerText contains the month string. If it does success, if not fail.