Count of number of times a css element appears on a page

911 views
Skip to first unread message

Erica S

unread,
Mar 23, 2015, 2:45:11 PM3/23/15
to nightw...@googlegroups.com
Hi,
 I have an element   with class name  "item_bluebutton"    I want to count how many times it appears on the  web page.  
 Any one know how to do this?

Thanks!

davidlinse

unread,
Mar 23, 2015, 4:07:47 PM3/23/15
to nightw...@googlegroups.com
first thing that popped in my mind.. 


module.export = {
  'Not Tested Demo of Count-Number-Of-Elements-With-Given-CSS-Class': function(browser) {
    browser.execute(function(selector){
      return document.querySelectorAll(selector).length;
    }, '.item_bluebutton', function callback(number_of_elements){
      browser.assert.ok(number_of_elements); // should pass
      browser.assert.equal(0); // should fail
    })
  }
}

regards
~david

Andrei Rusu

unread,
Mar 23, 2015, 4:07:56 PM3/23/15
to nightw...@googlegroups.com
Using the elements command.
> --
> You received this message because you are subscribed to the Google Groups
> "NightwatchJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nightwatchjs...@googlegroups.com.
> To post to this group, send email to nightw...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nightwatchjs/379d6497-a390-4cc3-a31f-d8ec04771517%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

davidlinse

unread,
Mar 23, 2015, 4:16:42 PM3/23/15
to nightw...@googlegroups.com
 Using the elements command. 

Much more elegant.. ;)
 

Erica S

unread,
Mar 24, 2015, 10:48:51 AM3/24/15
to nightw...@googlegroups.com
I am not sure what the ELEMENTS command is.

I know  elementPresent etc.

can you know me an example???

Romi Erez

unread,
Oct 15, 2018, 3:55:48 AM10/15/18
to NightwatchJs
Component.prototype.getNumOfElements = function(selector, callback) {
client.elements('css selector', selector, result => {
callback(result.value.length);
});
};
Reply all
Reply to author
Forward
0 new messages