Select Future Date in Calendar or Date Picker in webdriver

7,104 views
Skip to first unread message

neeraj bakhtani

unread,
Feb 5, 2013, 7:33:31 AM2/5/13
to webd...@googlegroups.com
Hi Friends,
Pls tell me how to Select Future date in the Date Picker.

Logic implemented in calendar is that "Effective date" is 50 days later from "Current date" appears in the Calendar.


Please See Screenshot.

Waiting for ur Valuable Replies.

Note:Text box of date is not editable so We cant use "Sendkeys".


Date.jpg

alladi sai

unread,
Feb 5, 2013, 10:37:47 PM2/5/13
to webd...@googlegroups.com
Hi Neeraj,

I am not sure in which bindings you are using ,

  1. Take the Current DateTime function from java/ .Net 
  2. Add the Days (50 or 51) to get the future date. 
  3. Now you have future date with you get the month,year and date from the Date store into some variables 
  4. Now click on the Date time picker. 
  5. And check date picker  current month text with stored month, if it's not equal click on the next month button in the calendar, do until u found the match.
  6. once you found match, find the link button of the day using stored Date and perform the action.
I hope it helps you.

Regard's
Sai baba




--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Regard's

Sai..

sheik fayaz

unread,
Feb 6, 2013, 2:09:38 AM2/6/13
to webd...@googlegroups.com
Hi Neeraj,

              You can make use of javaScriptExecutor to set the date directly in the text field.
              Below is the sample code:

          String FutureDate = "28/02/2013";
  String javaStringToSetDate = "var x=document.getElementsByName('flight_depart_date');x[0].value=" + "'" + FutureDate + "';";
          js.executeScript(javaStringToSetDate);

Best Regards,
Sheik



darrell

unread,
Feb 6, 2013, 8:06:27 AM2/6/13
to webd...@googlegroups.com
WebDriver deals with HTML, CSS and Javascript. There is no such thing as Date Picker in HTML, CSS, Javascript. There are plenty of libraries which will use the three technologies to create a date picker but how they implement this determines how WebDriver is going to be able to interact with it.

Bottom line, how to use a date picker is COMPLETELY dependent on how the date picker was implemented. If you know how to write a date picker you can usually look at the current implementation and figure out how to use it with WebDriver. If you are a hacker (in the good sense; i.e. learn by trial and error) you can usually figure out how to use the date picker with WebDriver. Final option is to have the developer who selected the date picker library help you with having WebDriver interact with it.

For example, if you look at source for http://jqueryui.com/datepicker/#inline you will see the date picker is actually a set of DIV and TABLE elements. I would write a WebDriver library which handles interacting with this date picker.

Additionally, WebDriver deals with the HTML code. A screenshot of the application really gives little information. Whenever I am implementing WebDriver code I look at the application HTML/DOM. Without tools like DevToolbar (F12 on IE) or Inspect in Chrome I would not be able to use WebDriver effectively.
Message has been deleted

Umamaheshwar Thota

unread,
Feb 8, 2013, 9:07:08 AM2/8/13
to webd...@googlegroups.com

Hi Neeraj,

If you are using Java use below code. It will generate the date 50 days from current date.

now = Calendar.getInstance();
now.add(Calendar.DATE, +50);
String FromDate =(now.get(Calendar.MONTH) + 1) + "/" + now.get(Calendar.DATE) + "/" + now.get(Calendar.YEAR);

You can use this using JavaScript Executor code below u can send it to the Element.

((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]", driver.findElement(By.id(OR.getProperty("txtSSTODate_ID"))), ToDate);

Cheers,
Umamaheshwar

David

unread,
Feb 17, 2013, 6:43:14 PM2/17/13
to webd...@googlegroups.com
Darrell is right on, for how to figure out proper solution.

Sometimes you may find that the text field you see is not actually the field that stores the date variable, rather instead a hidden input field is used to store the date value from the picker, and it would be this field that you then set via javascript as others have shown for how to set in terms of code.

By hidden field I mean <input type=hidden>

That's the case for the date picker we use at our place.
Reply all
Reply to author
Forward
0 new messages