2

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..

pageobject

 @FindBy(how=How.ID,using="booked_for")
        WebElement booked_for;
   public void setCalender(String strdate){
       // booked_for.clear();
        booked_for.sendKeys(strdate);
    }

pageobjectsteps

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

test

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
2

Try below code :

@FindBy(how=How.ID,using="booked_for")
WebElement booked_for;
public void setCalender(String strDate){
  //Code Here
  booked_for.clear();
  booked_for.sendKeys(strDate);
}

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 :

driver.findElement(By.id("booked_for")).sendKeys(strDate);

2. Initiate page object when your elements get changing :

AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);
 appointmentPageobj.booked_for.click();
AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);
 appointmentPageobj.setCalender(strdate);

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

Let me know if any query.

  • 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