InvalidElementStateException when attempting to clear text through Selenium

前端 未结 2 1079
小鲜肉
小鲜肉 2020-12-21 18:53

The web application I am testing requires confirmation when deleting a record.

I have created a test to enter in a valid reason for deleting this record.

Th

2条回答
  •  情书的邮戳
    2020-12-21 19:08

    As per the HTML you have shared the element with placeholder attribute as Removal reason is an Angular element and as you have to send text, you have to induce WebDriverWait for the element to be clickable as follows :

    IWebElement myElem = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='ng-valid md-input ng-not-empty md-autofocus ng-touched ng-dirty ng-valid-parse' and starts-with(@id,'input_') and @placeholder='Removal reason']")));
    myElem.Click();
    myElem.Clear();
    myElem.SendKeys("Automated Test - Delete Field");
    

    References

    You can find a couple of relevant discussions in:

    • How to clear text field before sending keys selenium c#
    • clear() does not clear the textbox with selenium and python and firefox
    • python selenium can't clear input field

提交回复
热议问题