protractor: WebElement.clear() Does Not Update Model
Calling WebElement.clear() on an input element does not appear to update the associated model.
View:
<input ng-model="foo">
<div>{{foo}}</div>
Spec:
it("should update the model", function(){
var input = element(by.css("input"));
input.sendKeys("bar");
input.clear();
expect(element(by.css("div")).getInnerHtml()).toBe(""); // Fails, because it's still "bar"
});
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 2
- Comments: 26 (8 by maintainers)
Commits related to this issue
- test(clear): show that clear() now works and updates the model Closes #301 — committed to kbaltrinic/protractor by juliemr 10 years ago
I had a similar issue with a directive I was using and sendKeys not updating the model. This solution worked for me though I am not sure if it will work for you all:
I can confirm this is still an issue with Angular 7.2.3 and Protractor 5.4.0 on 73.0.3683.103.
@wlingke thanks from 2017. I still have this issue on angular 2.
@wlingke thanks from 2018, lol. Still having this problem on Angular 5 when I try doing:
I’m no longer seeing this issue, and have pushed a test verifying the correct behavior. Please open a new issue if it’s still occurring for you!
@wlingke Thanks a lot! 2019 and this is still the way to go 😃
Still having this issue in 2017. On an input containing ‘abc’, .clear() followed by .sendKeys(‘d’) on the empty input field and results in ‘abcd’ in angular’s model using reactive forms.
@wlingke’s solution works only as long as you don’t try to run it on an operating system where CTRL is not set to the modifier key. It’s probably safer to run protractor.Key.BACK_SPACE * length of input value for now.