I need to create a testing tool using Nightwatch to extract titles from a simple list of items and store them in an array. For example, I want the array to contain: Coffee, Tea, Milk.
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Thank you for your help in advance.
EDIT>>
Thanks to @SoftwareEngineer171, I was able to use .execute() to inject JavaScript into Nightwatch and now it is functioning correctly. The following code retrieves the number of li items within an ol list (using CSS selector) with the help of @SoftwareEngineer171's code:
module.exports = {
'Demo' : function (client) {
client
.url('http://mylink.com/items')
.waitForElementVisible('body', 1000)
.execute(function(){
var arr = (function(a, b){
return (Array(a.length) + '').split(',').map(function(c, d){
return a[d].innerHTML;
});
})(document.getElementsByClassName("listing-view")[0].getElementsByClassName("listing-view-item"));
return arr;
}, ['arr'] ,function(result){
array_h1 = result.value
console.log(array_h1.length)
})
.pause(5000)
.end();
}
};