0

There is a calendar object in the web page, not developed internally. It's a datetime picker. How do I read the selected value from it through selenium ide?

Thanks in advance guys.

1
  • 1
    Datetime pickers are not part of the web-standards, what framework is your development team using to integrate the datetime picker. Maybe jQuery? – Niels van Reijmersdal Jun 2 '15 at 12:05
1

Datapicker is a table. So navigate the each cell. If a particular cell matches value xx then select it.

WebElement dataWidget = driver.findElement(By.id("ui-datapicker-div"));
List <webelement> rows=dataWidget.findElements(By.tagName("tr"));
List <webelement> columns=dataWidget.findElements(By.tagName("td"));
for (WebElement cell: columns){
  //Select xx. Date
  if(cell.getText().equals("15")){
    cell.findElement(By.linkText("15")).click();
    break;
  }
}
1
  • Like a 15th February. – Nergis Jun 2 '15 at 11:47
0

Not sure what time picker you are using but at my work this was a real pain. We use the Telerik Rad Date Picker which is common from my understanding. If there is no textbox associated with it to grab an ID and Text i would recommend encapsulating a method to run javascript and return a value. Each DatePicker should come with an API with different commands to set and retrieve the current selected date like so.

http://www.telerik.com/help/aspnet-ajax/calendar-client-side-basics.html

    public void setDate(String date)
    {

        String script = string.Format("$find('{0}').set_selectedDate(new Date('{1}'))", Id, date);
        util.runScript(driver, script);
    }

This is just an example of how i set the date but should be really beneficial by just plugging in the command to get the date as well.

0

If the calendar object you're using allows text input, even if it doesn't allow you to directly check the text of the input, you may still be able to select the text and copy it to the clipboard, then retrieve it there. Here is an example of something I've done in my own code:

IWebElement datePicker = Driver.FindElement(By.Id("ReminderDatePicker"));
datePicker.SendKeys(Keys.Control + "a");
datePicker.SendKeys(Keys.Control + "c");
string date = System.Windows.Clipboard.GetText();

The biggest catch to it is that you are modifying the contents of the system clipboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.