I cannot find the correct syntax to iterate through the innerHTML nodelist in Nightwatch. I am trying to return the URLs of each 'a' tag contained in the contents of the page body, but I cannot find a way to access the results of my querySelectorAll command in Nightwatch.
browser.execute(function() { return document.querySelectorAll("div.field-item.even a"); }, function(tags){ console.log(tags.value); console.log(tags.value[9]); })
There are 10 links on the page I'm testing. The query selector seems to retrieve all of them, since console.log (tags.value) prints the following:
[ { ELEMENT: '1' }, { ELEMENT: '2' }, { ELEMENT: '3' }, { ELEMENT: '4' }, { ELEMENT: '5' }, { ELEMENT: '6' }, { ELEMENT: '7' }, { ELEMENT: '8' }, { ELEMENT: '9' }, { ELEMENT: '10' } ]
and console.log (tags.value [9]) prints:
{ ELEMENT: '10' }
However, I cannot find a way to get the link from these results. Adding .innerHTML to any of these variables returns 'undefined'. Is there any way to iterate through the results of querySelectorAll and extract the urls inside it?
EDIT: It seems that I can get the same result if I use the following code:
browser.elements("css selector", "div.field-item.even a", function(tags) { console.log(tags.value); console.log(tags.value[9]); })
I initially thought that I was working with a nodelist, but I think that in fact they return a WebElement JSON object to me according to the documentation for the .elements command .
I still canโt access the inner text. Any ideas?