This post was most recently updated on June 14th, 2019
Difference between find element and find elements.
findElement() |
findElements() |
findElement() method used to access single web element |
findElements() method used to access multiple web elements. |
findElement() method returns first matching web element |
findElements() method returns list of all matching web elements |
If there is no matching web element then findElement() method throws exception |
If there is no matching web element then findElements() method returns empty list |
Usage of findElement() method:
1 2 |
<span style="font-size: 16px;">WebDriver driver = new ChromeDriver(); WebElement Element=driver.findElement(By.xpath("Xpath"));</span> |
Usage of findElements() method:
1 2 |
<span style="font-size: 16px;">WebDriver driver = new ChromeDriver(); List<WebElement> Elements= driver.findElements(By.xpath("Xpath"));</span> |