Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
216 views
by The go-to Tester (324 points)
closed by
Please describe, when do we use findElement() and findElements()?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
In selenium webdriver,

FindElement will return you the element found using your locator.

e.g. driver.findElement(By.id("username")); //will return username text box.

FindElement will return you List of elemnets found using that locator.

 e.g. driver.findElements(By.tagName("tr")); //will return you all rows in the table in form of List<WebElement>
 
You use findElement when you have only one element with that locator on the page. You use findElements when we want mutliple elements to be identified with the same locator type. 

Hope that helps!
 

 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...