【问题标题】:Angular testing: Protractor can't get input value角度测试:量角器无法获取输入值
【发布时间】:2013-10-23 09:41:33
【问题描述】:

我是 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() 返回''(空字符串)。

是否有不同的方法来捕获输入中的值?

提前致谢。

【问题讨论】:

    标签: javascript angularjs testing protractor


    【解决方案1】:

    显然 Selenium WebDriver 有一个怪癖。见here.

    试试:

    description.getAttribute('value');
    

    请注意,getAttribute 返回一个承诺,因此如果您需要以某种方式使用此值,则必须使用 then 子句:

    description.getAttribute('value').then(function(value){
        //Do something with value
    });
    

    【讨论】:

    • 通过使用 getAttribute 更改 getAttributes,它可以工作。谢谢!
    • 注意:getAttribute('value)` 返回一个承诺,所以你需要做这样的事情:getAttribute('value').then(function(value){ console.log(value) });
    • chromedriver: chromedriver_91.0.4472.101 元素值为null
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 2017-04-25
    • 1970-01-01
    • 2014-10-25
    • 2020-04-23
    • 1970-01-01
    相关资源
    最近更新 更多