Difference between findElement() and findElements() in SWD

Test Automation 0 Comment 15

The findElement( ) and findElements( ) both are methods of selenium WebDriver class.we can use these methods through an object of this class. The findElement( ) method is used to locate an element in the webpage source where as findElements( ) method is used to collect multiple similar elements from the webpage source. The  above methods uses a locator/query object known as <“By”>. There are various kinds of “By” strategies which you can utilise depending on your requirements. Their are 8 types of locators

  • By.id( )
  • By.name( )
  • By.tagname( )
  • By.cssselector( )
  • By.linktext( )
  • By.xpath( )
  • By.classname( )
  • By.partiallinktext( )

If located element is not found on the page then findElement( ) will throw NoSuchElementException.Whers as findElements( ) does not found  any element on current page as per given element locator mechanism, it will return empty list.


WebDriver obj= new FirefoxDriver();

//Here, the code below will send given data to the located field.//
obj.findElement(By.name(“Email”)).sendKeys(“//mail id//”);


// Here, the code below will select all rows matching the given XPath.//

List<WebElement> rows = obj.findElements(By.xpath(“//table/tr”));

obj.close( );


Related Articles

Leave a comment

You must be logged in to post a comment.

© 2016 4frienz. Powered By Flowers

Back to Top