I'm testing a website with Nightwatch and trying to get a collection of elements using the .elements() method.
I have the following code:
client.elements('css selector', 'p[class="f5 color-fg-muted mb-0 mt-1"]', function(elements) {
console.log(elements.value);
elements.value.forEach(item => {
console.log(item.ELEMENT);
});
});
The output is:
...
{
'element-6066-11e4-a52e-4f735466cecf': 'DE70929C2F5311AC55FD8AFEE548EA6D_element_178'
},
{
'element-6066-11e4-a52e-4f735466cecf': 'DE70929C2F5311AC55FD8AFEE548EA6D_element_179'
},
{
'element-6066-11e4-a52e-4f735466cecf': 'DE70929C2F5311AC55FD8AFEE548EA6D_element_180'
},
... 80 more items
]
undefined
undefined
undefined
undefined
...
Mentioned selector points to a couple of p elements and all I want is to get the text from them.
(p elements on a page)
What should I do to get exactly p (not "element-6066-11e4-a52e-4f735466cecf") elements and then the text of them?
After the
forEachI believe you get the Node object. Try accessing it directly.