NightwatchJS:如何检查属性是否不存在?

时间:2016-09-07 11:15:06

标签: javascript node.js selenium nightwatch.js

我想使用NightwatchJS检查disabledbutton属性是否

我尝试过这样做:

  • .assert.attributeContains('.phone-verify-btn', 'disabled', 'null')

  • .assert.attributeContains('.phone-verify-btn', 'disabled', null)

  • .assert.attributeContains('.phone-verify-btn', 'disabled', 'false')

  • .assert.attributeContains('.phone-verify-btn', 'disabled', false)

但这些似乎并不像他们那样检查disabled是否设置为true,如此:

  • .assert.attributeContains('.phone-verify-btn', 'disabled', 'true')

这很好用!知道这里发生了什么吗?我得到的错误相当神秘:

Element does not have a disabled attribute. - expected "null" but got: null

2 个答案:

答案 0 :(得分:2)

在这种情况下,我认为你应该首先得到属性,直到我们有更好的解决方案。这个对我有用:

 Browser.getAttribute('@element','disabled',function(result){
   if(result.value === 'true'){
      // element is disabled , do what you want
   }
   // element not disabled .
  })

也许这不合逻辑!

答案 1 :(得分:1)

更改attribute包含为attributeEquals

.assert.attributeEquals('.phone-verify-btn', 'disabled', null)