Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nightwatch js how to assert multiple elements

i'm trying to assert/verify multiple elements for an attribute with Nightwatch.js.

I tried to use the "elements" command by selenium but it seems to not actually return a tag.

browser.elements('css selector','icon_checkmark', function (result) {
    this.verify.attributeEquals(result.value, 'aria-hidden', 'true');
})

The console outputs this error:

Testing if attribute aria-hidden of <[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]> equals "true". 
Element could not be located.  - expected "true" but got: null
ERROR: Unable to locate element: "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" using: css selector

It seems like it finds the right things because there should be 6 but then somehow I read out the wrong thing? Console.log of result.value[0] gives just { ELEMENT: '19' } which seems correct.

Any idea how could I make this work? I want to check if all elements with the class icon_checkmark have an attribute aria-hidden="true".

like image 383
Stefanie Avatar asked Nov 24 '14 23:11

Stefanie


1 Answers

attributeEquals locate element using css selector, while elements returns ID of element, so you can't locate the element that way. You can use elementIdAttribute to get the element and verify it.

browser.elements('css selector','icon_checkmark', function (result) {
  result.value.map(function (v, k) {
    browser.elementIdAttribute(v.ELEMENT, 'aria-hidden', function (res) {
      // true
      return browser.assert.equal(res.value, 'expected value');
    });
  });
})
like image 79
Tinple Avatar answered Oct 17 '22 01:10

Tinple