更新时间:2022-04-11 06:04:43
此错误消息...
invalid element state: Element must be user-editable in order to clear it.
...表示所标识的元素不是处于用户可编辑状态,无法调用clear()
方法.
...implies that the element identified was not in a user-editable state to invoke clear()
method.
要在带有 Angular 元素的下拉列表中插入日期,有两种方法:
To insert a date with in a dropdown-toggle with an Angular element there are two approaches:
click()
并使用sendKeys()
executeScript()
调用removeAttribute()
只读属性.click()
on the calendar and insert a date using sendKeys()
executeScript()
to invoke removeAttribute()
the readonly attribute.However, as per the HTML you have shared it seems the element which gets populated with the date string i.e. 2019/11/21 is not readily available within the HTML DOM. So we can infer that the following element gets added to the DOM Tree as a result of interaction with other WebElements which is as follows:
<p ng-if="displayEndDate" class="ng-binding ng-scope">2019/11/21</p>
因此***的方法是
click()
.sendKeys()
.代码块:
click()
on the element readily available within the HTML inducing WebDriverWait.sendKeys()
on the newly created element WebDriverWait.Code Block:
//element -> myclass.SetDateByXpath("//a[@class='dropdown-toggle' and @id='enddate-dropdown']"
// observe the change in the ^^^ xpath ^^^
//value -> myclass.GetDate("yyyy/MM/dd", mydate));
public void SetDateByXpath(String element, String value)
{
WebElement webElement = ExplicitWaitOnElement(By.xpath(element));
webElement.click();
WebElement webElement_new = ExplicitWaitOnElement(By.xpath("//a[@class='dropdown-toggle' and @id='enddate-dropdown']//p[@class='ng-binding ng-scope' and @ng-if='displayEndDate']"));
webElement_new.clear();
webElement_new.sendKeys(value);
}
您可以在以下位置找到相关讨论:
You can find a relevant discussion in: