2017-02-14 54 views
0

请建议我,如何删除分区。我正在绞杀波纹管代码,但这不适用于拆除部门。 我已经使用javascript和jquery删除div,但它没有在casperjs上工作。所以我希望casperjs中的解决方案能像div一样去除html元素。如何删除casperjs的分区

casper.then(function() { 
     this.wait(10000, function() { 
      var elems = []; 
      var outputlength = this.getElementsInfo('.context').length; 

      for (var i = 0; i < outputlength; i++) 
      { 
       var as = this.getElementsInfo('#context_' + i + ' .a').length; 
       var elems = []; 
       var isDelete = false; 
       for (var j = 0; j < as; j++) 
       { 
        var text = this.fetchText('#b_' + i + '_' + j); 
        x = text.split(" "); 

        if (elems.length == 0) { 
         elems.push(x[0]); 
        } else if (elems.indexOf(text) == -1) { 
         isDelete = true; 
         break; 
        } 
       } 
       if (casper.exists('#context_' + i + '.notAvailableCell')) 
       { 
        isDelete = true; 
       } 
       if (isDelete) { 
        this.wait(2000, function() { 
         this.evaluate(function() { 
          $('#context_' + i).remove(); 
         }); 
        }); 
       } 
      } 
      this.wait(2000, function() { 
       this.capture("screenshot.png"); 
      }); 
     }); 
    }); 

回答

0

我发现通过使用jquery和casperjs动态去除除法的解决方案。

this.evaluate(function (d) { 
    $('#context_' + d).remove(); 
    return d; 
}, i); 

现在它对我来说工作正常。