ducin ducin - 1 year ago 236
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download