1.

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

Answer»

The MAIN difference between driver.FINDELEMENT() and driver.FINDELEMENTS() commands is-

findElement() returns a single WebElement (which is found first) based on the locator PASSED as the parameter. Whereas findElements() returns a list of WebElements satisfying the locator VALUE passed. It returns an empty list if there are no web elements matching the locator strategy.

Syntax of findElement()-

WebElement textbox = driver.findElement(By.id(“textBoxLocator”));

Syntax of findElements()-

List <WebElement> elements = element.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.



Discussion

No Comment Found