I am writing an automated test in Java using Selenium2/WebDriver. I need to validate a birthday in the future is not allowed. To get tomorrow’s date, I am using:
Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1);
I am having trouble printing that to a text field, since .sendKeys requires characters. Any help is appreciated. I’m also unsure if that is the best way to get tomorrow’s date.
Your code is basically right. Use a
Calendarto produceDateobjects:Use
SimpleDateFormatto format theDateas aString:Prints:
You can use Selenium to send those
Stringobjects to the date control (if it accepts keyed input, of course). You’ll need to adjust the date pattern"dd-MMM-yyyy"to match the format expected by the input control on the page, e.g. perhaps it’s ("MM/dd/YY")?