how to loop though elements in nightmare js

Viewed 503

Im doing a project for my JS class. I want to build a nightmare.js script that sends a message to every product post on close5.com within a location.

I already figured out how to login and send a message to a single product but I cant figure out how to loop through all product send a message and the click "Show More" then do the next 20 products

This is what i have so far

var Nightmare = require('nightmare');
var startingLink = "https://www.close5.com/l/los_angeles-california"
var nightmare = Nightmare({ show: true });

nightmare
//login code
  .goto('https://www.close5.com/login')
  .type('input[name="email"]', 'email@email')
  .type('input[name="password"]', 'password') 
  .click('.button__root__3pI8a')
  .wait(600)
//end login code

  .goto(startingLink)
  .evaluate(function() {

    var elements = Array.from(document.getElementsByClassName('ItemsListCard__item__8yykb'));


    return elements.map(function(element) {

       .click('.ItemListingActionButtons__ask__3x7L_')
       .type('.ThreadViewInput__input__37Ra7', 'random test msg')
       .click('.ThreadViewInput__send__2FcoR')

    });
  })

  .end()
  .then(function(content) {
    console.log(content);

  })

how do i loop though every element and click then send the message? how to you click a element inside .evaluate()?

0 Answers
Related