group-icon
Software Testing Squad
All About Software Testing In One Place!
127 Members
Join this group to post and comment.
Shruthi Pillai
Shruthi Pillai
Information Technology
12 Feb 2019

What is the difference between findElement() and findElements() in selenium?

findElement(): It is used to find the first element within the current page using the given "locating mechanism". It returns a single WebElement.

findElements(): It uses the given "locating mechanism" to find all the elements within the current page. It returns a list of web elements.


Archana Priyadarshini
Archana Priyadarshini
Computer Science
2mos ago

findElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.

findElements method returns the list of all matching elements. The findElement method throws a NoSuchElementException exception when the element is not available on the page. Whereas, the findElements method returns  an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.