ducin ducin - 2 months ago 34
Javascript Question

phantomjs/casperjs count DOM elements

I would like to count the number of, let's say, div elements with 'nice' class. I've got the selector

, but don't know which casperjs class/method to use.

There is a tester.assertElementCount method in fact, but is there anything that simply returns the number of elements?


If you can use jquery its fairly simple:

var count = $('div.classname').length;

Found an SO Post that seems to explain using jquery with casperjs, I have no experience with casperjs so I can't help much there.