Monday, 29 May 2017

Electron Nightmare.js NodeList to Array

I'm trying to iterate through a NodeList obtained via Nightmare.js. Executing in the dev tools performs as expected, but in ElectronI can't convert the NodeList to array successfully.

   nightmare
  // Open Amazon Home page & Login 
  .goto('https://www.somePage.com')
  .wait('#someID')
  .evaluate(function () {
    var links = document.querySelectorAll('div.someClass')
    return links;
  })
  .end()
  .then(function (result) {
    console.log(result); // outputs the NodeList successfully. 
    var nodesArray = Array.prototype.slice.call(result);
    console.log(nodesArray.length) // Always 0 
    })
   .catch(function (error) {
      console.error('Failed', 
      error);
    })
  

I've tried porting the NodeList by various other methods. Nothing seams to work in Electron. Again, this is easily achieved in chrome tools.



via Antecmo

No comments:

Post a Comment