What is the difference between driver.findElement() and driver.findElements() commands?
Hello Tim-khorev,
The difference between driver.findElement()
and driver.findElements()
commands are-
findElement()
returns a single WebElement (found first) based on the locator passed as a parameter. Whereas findElements() returns a list of WebElements, all satisfying the locator value passed.
Syntax of findElement()-
WebElement textbox = driver.findElement(By.id(“textBoxLocator”));
Whereas the syntax of findElements()-
List <WebElement> elements = driver.findElements(By.id(“value”));
Another difference between the two is – if no element is found then findElement()
throws NoSuchElementException whereas findElements()
returns a list of 0 elements.