Select date from a calendar in Selenium Webdriver

  • I am trying to select a date from the calendar. However sendkeys does not send data. After I click on the field calendar month drops down. Right click reveals nothing. I have tried in Firefox and Chrome.

    @FindBy(xpath = "//input[@name='dob']")  
    private WebElement selectCustomerDOB;
    public void sendDOB(String dob){                 

    I have tested with Thread.sleep to make sure it is not a timing issue.

    What can I do in this case to select a date? Thanks in advance for your time and ideas.

  • Since you are using an element with type 'date', it is up to the browser to render the calendar, or anything else to allow users to select the date. The date picker is not part of your web page and so you would not be able to find its locators in the conventional ways.

    I believe your testing requirement is to be able to check how your application behaves when different dates are selected, rather than to see if the date picker works (which the browser would take care for you).

    In order to select dates, you should be able to use send keys if you gave the value in the right format (yyyy-MM-dd). I tested with the given website using Selenium IDE and things seem to work.

    WebElement selectCustomerDOB = driver.findElementById("dob"); // While xPath is great and your xPath is valid - I feel ID is much faster.

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2