I am in stuck using with calender automate I want to automate a calender using with selenium. I am following page object design pattern.

here is my code..


        WebElement booked_for;
   public void setCalender(String strdate){
       // booked_for.clear();


AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);


AppointmentPage ex=log.Valid("986444545","antony","anto@gmail.com","Demo","2017-03-04","Dr.John");

Error :

org.openqa.selenium.InvalidElementStateException: invalid element state: Element must be user-editable in order to clear it.

Inspect code :

<input type="text" id="booked_for" value="2017-03-02" name="booked_for" readonly="" class="form-control type-num date-inp">

Couldn't automate the calender and clear() is get error

  • Date controls are often very tricky to automate. One workaround I use is to automate them with screenshot-based tools such as Selenium plus Sikuli or Kantu. – Bobby231 Mar 2 '17 at 13:27

Try below code :

WebElement booked_for;
public void setCalender(String strDate){
  //Code Here

Here Need to know below things :

  1. Please provide input. Here strDate is input.
  2. Try to use proper ID,name , xpath, css etc.
  3. Try to avoid override methods.

Alternative solution :

Click on date element. Get element of Date, Month and Year and select it. For this you need to create one method which can read date and select as per input.

Solution of new edit of question :

org.openqa.selenium.InvalidElementStateException: invalid element state this exception says, Web page elements get change after some user events or more specific HTML element is getting change in their properties run time like class.

  • So here I have two different ways to solve this error.

Kindly use as per requirements and feasibility with code :

1. Use element directly like below :


2. Initiate page object when your elements get changing :

AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);
AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);

Here first we click on calendar then get new page object repo and send our new date.

Let me know if any query.

| improve this answer | |
  • Hello Sir, This question is different from another one. If now you can able to select date then this answer should be accepted. For another scenario you have already raised another question. I am requesting you to kindly accept answer so many people can learn and trust this answer. – Sagar007 Mar 3 '17 at 7:27

Your Answer

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