javascriptautomated-testsnightwatch.jsnightwatch

How .elements() works in nightwatch?


Considering I have multiple trs I want to pick one and edit value in it by clicking edit button bounded to it.

I'm doing something like this:

browser.elements('css selector', '#someId  tr', elements => {
  elements.value.forEach(val => {
    console.log(val)
  }

And I get something like this:

{
  'abcd-1234-qwer-0987': 'some id'
},
{
  'abcd-1234-qwer-0987': 'some other id'
}
  1. What is exactly 'abcd-1234-qwer-0987', is this session id kind of stuff and does it change?
  2. What is the best way to grab particular element? Because as I guess my approach is wrong: elements.value[1]['abcd-1234-qwer-0987']

Solution

  • Its return the elements items are Web Element json objects. that a Web Element ID

    https://nightwatchjs.org/api/commands/#elements

    1.What is exactly 'abcd-1234-qwer-0987', is this session id kind of stuff and does it change?

    yes it will change according to Session

    2.what is the best way to grab particular element

    refer the below

    Using Nightwatch, how do you get the DOM element, and it's attributes from the ELEMENT entity?

    browser.elements('css selector', '#someId  tr', elements => {
     console.log(elements);
    elements.value.forEach(element =>{
    let key = Object.keys(element)[0];
    let ElementIDvalue = element[key];
    console.log("key = ",  key);
    console.log("WebElementIDvalue = ", ElementIDvalue);
    })
    });