top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When do we use findElement() and findElements() in Selenium?

+1 vote
558 views
When do we use findElement() and findElements() in Selenium?
posted Oct 25, 2016 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.

Syntax:

WebElement element = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.

Syntax:

List elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

answer Nov 2, 2016 by Manikandan J
...