'Nightwatch JS | Looping/Iterating through Table

I've been working with Nightwatch for a few months now, using the page object method to try and make my tests as modular as possible. I've ran into a block on my knowledge over javascript syntax, and haven't been able to move past it.

I have a calendar table bracket, which displays in a block, that houses a plethora of child objects. Each object has individual attributes which all have similar values, each differing based on the date respective to that object.

I have been unable to select any date just based on its class values, so I opted to create an iterative loop that would go through all of the visible fields, and click on one with a highlighted class; as a means of selecting the current date automatically. My only issue is that I have had no success creating this loop after reading all of the Nightwatch documentation, and going through many previous users' issues before me.

This is the basic HTML breakdown for each column located within the container's body:

<div id=[container class] class=[container class] <div class=[container header class] <table class=[table class] <tbody> <tr> <td>

Based on some of the web articles I've read, the loop structure to use would be to use the .elements() command to call the elements in question, and then use a .forEach() command to loop through it, and eventually call the value to click on it. I believed I had come to the correct syntax on writing this, but I get a lot of different errors ranging from unexpected '.' to noSuchElement.

The following code snippet is what I have been trying to use, but have had no success.

.elements('css selector', 'table.ui-datepicker-calendar > tbody > tr > td', function(elements) { elements.value.forEach(function(elementsObj, index) { .elementIdAttribute(elementsObj.ELEMENT, 'class', function(result) { if (index == 'ui-datepicker-today') { browser.elementIdClick(result.value) } }) }) })

Is there a better way to try and achieve this that I am unaware of?

Update: As I work through this and try different strategies, I have been able to narrow down some of the issue here. I have edited the code block I am trying to run here:

      browser.elements('css selector', '.ui-datepicker-calendar > tbody > tr > td', function (elements) {
        elements.value.forEach(function (elementsObj, index) {
            browser.elementIdAttribute('elementsObj.ELEMENT', 'class', function (result) {
              if (index == '.ui-datepicker-today') {
                browser.elementIdClick('result.value')
            }
          })
        })
      })

and get an error right around:

browser.elementIdAttribute('elementsObj.ELEMENT', 'class', function (result)

The error reads:

     value: {
       error: 'no such element',
       message: 'no such element: Element_id length is invalid\n' +
         '  (Session info: chrome=99.0.4844.84)',
       stacktrace: ''
     }

I'll be honest, I have never seen an error message say that in my life. I am unsure what exactly it means, and the only documentation I can find through web search is related to another testing framework separate to Nightwatch.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source