最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NightwatchJS: How to check if attribute is not present? - Stack Overflow

programmeradmin1浏览0评论

I want to check if a disabled attribute is not present on a button using NightwatchJS.

I tried doing these:

  • .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)

But these don't seem to work like they do to check if disabled is set to true like so:

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

This works just fine! Any idea what's happening here? The error I get is rather cryptic:

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

I want to check if a disabled attribute is not present on a button using NightwatchJS.

I tried doing these:

  • .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)

But these don't seem to work like they do to check if disabled is set to true like so:

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

This works just fine! Any idea what's happening here? The error I get is rather cryptic:

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

Share Improve this question edited Sep 7, 2016 at 11:23 nikjohn asked Sep 7, 2016 at 11:15 nikjohnnikjohn 22k15 gold badges56 silver badges88 bronze badges 1
  • I have the exact same problem. What I'm currently doing is .assert.elementNotPresent('.phone-verify-btn[disabled]'), but I also would like a cleaner solution. – Adam Zerner Commented Aug 6, 2018 at 0:14
Add a ment  | 

2 Answers 2

Reset to default 2

In this case,I think you should get attribute first until we have better solution. This one works for me :

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

Perhaps it is not really logical !

Change attributeContains to attributeEquals

.assert.attributeEquals('.phone-verify-btn', 'disabled', null)
发布评论

评论列表(0)

  1. 暂无评论