我是 Protractor 的新手..尽管缺少文档,但我认为我理解了基本原理,但我找不到解决这个问题的方法。
给定这段代码:
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');
我可以看到输入获取了它正在插入的文本,并且模型更新了相同的值,但是测试失败是因为 description.getText() 返回了“”(空字符串)。
是否有不同的方法来捕获输入中的值?
提前致谢。
最佳答案
显然,Selenium WebDriver 有一个怪癖。参见 here.
尝试:
description.getAttribute('value');
请注意,getAttribute
返回一个 promise ,因此如果您需要以某种方式使用此值,则必须使用 then
子句:
description.getAttribute('value').then(function(value){
//Do something with value
});
关于javascript - Angular Testing : Protractor can't get input value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19538185/