admin管理员组文章数量:1356898
I'm using angularJS to develop an application. To test it I use protractor.
I want to check the value in an input area. This is my input:
<input id="rank-max-range" class="form-control has-feedback" name="inputMax" type="number" placeholder="Maximum" ng-model="selectedItem.range.max" min="{{selectedItem.range.min}}" max="{{selectedItem.answers.length}}">
And this is the test:
it('should be fill the max range with the given value', function() {
element(by.id('rank-max-range')).sendKeys(2);
expect(element(by.id('rank-max-range')).getText()).toEqual(2);
});
The problem is it didn't work. I found on the documentation that it is possible to use getAttribute('value')
. But in my case there is no value attribute on my input.
I wonder if it possible to check the content of the ng-model
but I didn't find the solution.
Do you have an idea of how I could achieve this test?
I'm using angularJS to develop an application. To test it I use protractor.
I want to check the value in an input area. This is my input:
<input id="rank-max-range" class="form-control has-feedback" name="inputMax" type="number" placeholder="Maximum" ng-model="selectedItem.range.max" min="{{selectedItem.range.min}}" max="{{selectedItem.answers.length}}">
And this is the test:
it('should be fill the max range with the given value', function() {
element(by.id('rank-max-range')).sendKeys(2);
expect(element(by.id('rank-max-range')).getText()).toEqual(2);
});
The problem is it didn't work. I found on the documentation that it is possible to use getAttribute('value')
. But in my case there is no value attribute on my input.
I wonder if it possible to check the content of the ng-model
but I didn't find the solution.
Do you have an idea of how I could achieve this test?
Share Improve this question edited Jun 12, 2015 at 10:43 alecxe 474k127 gold badges1.1k silver badges1.2k bronze badges asked Jun 12, 2015 at 10:33 MtoypcMtoypc 4941 gold badge7 silver badges24 bronze badges2 Answers
Reset to default 7Normally getAttribute('value')
should work. getText()
won't work because input elements don't have inner text.
expect(element(by.id('rank-max-range')).getAttribute('value')).toEqual(2);
Have you tried to log the result of getAttribute('value')
?
getText()
would not definitely work, since this is an input
and it's value would be inside the value
attribute, once set. The HTML you've presented does not contain value
because this is a source HTML when the page is not rendered and the value is not set. getAttribute('value')
is the way to go here:
var numberInput = element(by.id('rank-max-range'));
numberInput.sendKeys("2");
expect(numberInput.getAttribute('value')).toEqual("2");
You can actually see the value
being set by dumping the innerHTML
on the console:
numberInput.sendKeys("2");
numberInput.getInnerHtml().then(function (html) {
console.log(html);
});
I wonder if it possible to check the content of the ng-model but I didn't find the solution.
You can use evaluate()
to see/check the value of the model:
expect(numberInput.evaluate('selectedItem.range.max')).toEqual(2);
本文标签: javascriptCan39t get the value in an input with protractorStack Overflow
版权声明:本文标题:javascript - Can't get the value in an input with protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744044976a2581356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论