javascript 量角器获取模型值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29114098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Protractor Get Model Value
提问by Sumit
I am new to ProtractorJS. What I am trying to do is trying to get the value of a disabled input element. This input element is bound to a model. Initially this input element is empty; then after some action the model value is updated (and thus displayed in input element). I need to get that value, how can I do that ?
我是 ProtractorJS 的新手。我想要做的是尝试获取禁用输入元素的值。此输入元素绑定到模型。最初这个输入元素是空的;然后在一些操作之后更新模型值(并因此显示在输入元素中)。我需要获得那个价值,我该怎么做?
My input element is:
我的输入元素是:
<input class="form-control ng-pristine ng-valid" style="font-size: 11px;" disabled="disabled" type="text" ng-model="Promotion.PrometricID">
I am trying to fetch value by:
我试图通过以下方式获取价值:
element(by.model("Promotion.PrometricID")).getAttribute('value');
But whenever I write the value in console it gives me "[object] [object]".
但是每当我在控制台中写入值时,它都会给我“[object] [object]”。
Can anyone please tell me how to find value in this text box or in model ?
谁能告诉我如何在此文本框或模型中找到值?
回答by alecxe
It is just because getAttribute()
returns a promise.
这只是因为getAttribute()
返回一个 promise。
You need to resolve itif you want to see the result on the console:
如果你想在控制台上看到结果,你需要解决它:
var elm = element(by.model("Promotion.PrometricID"));
elm.getAttribute('value').then(function (value) {
console.log(value);
});
FYI, exploring The WebDriver Control Flowdocumentation page should clear things up.
仅供参考,探索WebDriver 控制流文档页面应该可以解决问题。
回答by Luis Kimura
this way worked for me:
这种方式对我有用:
element(by.binding('Promotion.PrometricID')).getText().then(function (value) {
console.log(value);
})
回答by Bwyss
My solution:
我的解决方案:
element(by.model('Promotion.PrometricID')).getText().then(function (value) {
console.log(value);
});