Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding multiple elements

I can't seem to figure out the best way to find multiple elements on a page.

It always finds one but what if I'm testing to see how many particular elements are present after some kind of action?

findElement() // always returns 1 element
findElements(By.className('someClass')) // always returns 1 element
like image 413
volk Avatar asked Sep 07 '13 20:09

volk


People also ask

How do I use the find element method?

When the find element method is called on the driver instance, it returns a reference to the first element in the DOM that matches with the provided locator. This value can be stored and used for future element actions.

How to locate multiple elements at the same time in selenium?

We can locate and identify multiple elements at the same time in Selenium. There are various strategies to locate the elements. The different ways of locating elements are listed below − find_elements_by_xpath – This method returns all the elements with matching xpath in the argument in form a list.

How to find the two repeating elements in a given array?

Find the two repeating elements in a given array. You are given an array of n+2 elements. All elements of the array are in range 1 to n. And all elements occur once except two numbers which occur twice. Find the two repeating numbers. For example, array = {4, 2, 4, 5, 2, 3, 1} and n = 5.

How do you find the number of repeating elements in JavaScript?

Since, the size of the array is n+1 and elements ranges from 1 to n then it is confirmed that there will be at least one repeating element. A simple solution is to create a count array and store counts of all elements. As soon as we encounter an element with count more than 1, we return it.


1 Answers

In case someone looks for this in the future, I got it to work:

findElements(By.className("someclass")).then(function(elements_arr){ 
    console.log(elements_arr.length);
});

According to their source code, findElements returns a promise

Webdriverjs API

like image 156
volk Avatar answered Sep 22 '22 15:09

volk