javascript 角度测试:量角器无法获取输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19538185/
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
Angular testing: Protractor can't get input value
提问by Vito Schiavo
I'm new to Protractor..I think I understood the basic principles in spite of the lacking documentation, but I can't find a way to solve this problem.
我是 Protractor 的新手。尽管缺乏文档,我想我理解了基本原理,但是我找不到解决这个问题的方法。
Given this code:
鉴于此代码:
ptor.findElement(protractor.By.input('canvas.description')).sendKeys('My description');
var description = ptor.findElement(protractor.By.input('canvas.description'));
expect(description.getText()).toEqual('My description');
I can see that the input gets the text it's inserting and the model updates with the same value, but the test failures 'cause description.getText() returns '' (empty string).
我可以看到输入获取了它插入的文本,并且模型更新为相同的值,但测试失败,因为 description.getText() 返回 ''(空字符串)。
Is there a different way to catch values inside inputs?
是否有不同的方法来捕获输入中的值?
Thanks in advance.
提前致谢。
回答by preeve
Apparently there is a quirk with Selenium WebDriver. See here.
显然,Selenium WebDriver 有一个怪癖。看到这里。
Try:
尝试:
description.getAttribute('value');
Note, that getAttribute
returns a promise, so if you need to use this value somehow you'll have to use a then
clause:
请注意,这会getAttribute
返回一个承诺,因此如果您需要以某种方式使用此值,则必须使用then
子句:
description.getAttribute('value').then(function(value){
//Do something with value
});