Click on all links matching a selector

前端 未结 3 1592
抹茶落季
抹茶落季 2020-12-19 05:22

I have a list of links that I have to simulate a click on using CasperJS. They all share the same class.

However using this.click(\'.click-me\') only cl

3条回答
  •  情深已故
    2020-12-19 05:38

    I ended up using the nth-child() selector to accomplish this. Here's how...

    Page:

    
    

    Script:

    casper.then(function() {
      var i = 1;
      this.repeat(3, function() {
        this.click('#links li:nth-child(' + i + ') a');
        i++;
      });
    });
    

    You obviously don't have to use repeat but any iteration technique should work.

提交回复
热议问题