1.

What is the difference between driver.findElement() and driver.findElements() commands?

Answer»

The distinction between driver.findElement() and driver.findElements() commands is-

  • findElement() - Based on the locator supplied as an ARGUMENT, findElement() RETURNS a single WebElement which is found first. If no element is discovered, it throws the NoSuchElementException.

findElement() has the following syntax:

WebElement textbox = driver.findElement(By.id("textBoxLocator"));
  • findElements() - Based on the locator supplied as an argument, findElements(), on the other HAND, produces a list of WebElements that all satisfy the location value supplied. If no element is discovered, it does not THROW any exception and returns a list of ZERO elements.

findElements() has the following syntax:

List <WebElement> elements = element.findElements(By.id("value"));


Discussion

No Comment Found