Counting elements with the same selector in webdriver.io Counting elements with the same selector in webdriver.io selenium selenium

Counting elements with the same selector in webdriver.io


This is how you do it:

client.elements('.myElements', function(err,res) {    console.log('element count: ',res.value.length);});

Explanation: with elements you fetch all elements according given selector. It returns an array of webdriver elements which represents the amount of existing elements on the page.


For version 4 of webdriver.io, this is the way

client.elements('.selector').then(function (elems) {    console.log(elems.value.length);});


Or you can write to a variable and later use it

let smth = browser.elements('selector').value.length;