I am trying to make simple follow script with Nightmarejs. It should work in next way:
- Go to some user profile
- Click on button to open list of followers of that user
- Click all follow buttons with delay between each click
- Click load more
- Repeat step 3. and 4. few times
What I have so far is this, and it works with no errors, but it clicks only on first follow button and that is end:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://example.com/')
.click('.buttonOpenModal')
.wait(4000)
.click('.buttonFollow')
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
I tried to loop clicking on follow buttons like this but it gives me error $ is not defined
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://example.com/')
.click('.buttonOpenModal')
.wait(4000)
.evaluate(function(){
$('.buttonFollow').each(function() {
$(this).click();
});
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
I believe that for someone who is experienced in Nightmarejs this will be simple task, but I just started with it and been struggling with it for 2 days now.
I would really appreciate any help.