Validate date in dropdownlist

Ask general questions here.
Posts: 5
Joined: Fri Jan 09, 2015 4:46 am

Validate date in dropdownlist

Post by ViMac » Thu Dec 17, 2015 4:28 am

How can I validate date that's input using 3 drop-down lists are day, month, year?
date-dropdownlist.png (4.09 KiB) Viewed 722 times
Please kindly consider and advise. I'm looking forward to everyone reply.

User avatar
Ranorex Guru
Ranorex Guru
Posts: 4135
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Validate date in dropdownlist

Post by odklizec » Thu Dec 17, 2015 8:42 am


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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: Validate date in dropdownlist

Post by Martin » Thu Dec 17, 2015 9:07 am


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

Guide here: ... 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

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.