InvalidElementStateException when attempting to clear text through Selenium

前端 未结 2 1065
小鲜肉
小鲜肉 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 <input> 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
    0 讨论(0)
  • 2020-12-21 19:22

    I was having the same issue, only I was trying to enter a dash in a date field that didn't allow dashes. I figured this out by manually entering a date with a dash and it did not populate. (The field also doesn't accept letters - just numbers). Now, my test enters a date without a dash and it passes successfully!

    0 讨论(0)
提交回复
热议问题