I'm trying to click on this calendar and insert a date automatically using selenium, but I got the error below:
invalid element state: Element must be user-editable in order to clear it.
HTML snippet
<a id="enddate-dropdown" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="">
<p class="custom-datepickers__date-prefix ng-binding">To:</p>
<!-- ngIf: displayEndDate -->
<!-- ngIf: !displayEndDate --><div ng-if="!displayEndDate" class="custom-datepickers__no-date ng-scope"></div><!-- end ngIf: !displayEndDate -->
</a>
Code snippet
myclass.SetDateByXpath("//*[@id=\"enddate-dropdown\"]/p", myclass.GetDate("yyyy/MM/dd", mydate));
public void SetDateByXpath(String element, String value)
{
WebElement webElement = ExplicitWaitOnElement(By.xpath(element));
((JavascriptExecutor) driver).executeScript(
"arguments[0].removeAttribute('readonly','readonly')",webElement);
webElement.clear();
webElement.sendKeys(value);
}
If I set the date manually, this is the HTML:
<a id="enddate-dropdown" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="">
<p class="custom-datepickers__date-prefix ng-binding">To:</p>
<!-- ngIf: displayEndDate --><p ng-if="displayEndDate" class="ng-binding ng-scope">2019/11/21</p><!-- end ngIf: displayEndDate -->
<!-- ngIf: !displayEndDate -->
</a>
Probably the website changed, but now I don't know how can I set this value. Any help will be appreciated.
Thanks