Skip to content

Instantly share code, notes, and snippets.

@Tirael
Created November 24, 2016 16:15
Show Gist options
  • Save Tirael/8b5707f7e188fcd6fb720d9d1ee27b0d to your computer and use it in GitHub Desktop.
Save Tirael/8b5707f7e188fcd6fb720d9d1ee27b0d to your computer and use it in GitHub Desktop.
Nightmarejs .click() on each element with delay between
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('http://example.com/')
.click('.buttonOpenModal')
.wait('div.Buttons')
.evaluate(function () {
var interval = setInterval(function () {
var btn = document.querySelectorAll('div.Buttons');
if (undefined == btn || 0 == btn.length) {
clearInterval(interval);
}
else {
btn[0].click();
}
}, 5000);
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment