SELENIUM BASICS:


SELENIUM WEBDRIVER:


TESTNG:


REPORTS:


BUILD & CONTINUOUS INTEGRATION TOOLS:


CROSS BROWSER TESTING:


MOBILE TESTING:


AUTOMATION FRAMEWORKS:


API Testing:


INTERVIEW QUESTIONS:


SAMPLE RESUME:

Difference Between FindElement And FindElements Methods

To automate a web application using Selenium WebDriver, we need to locate the elements on a web page. We use different locators depends on our needs to find the elements. Here is a link to the post “Locators in Selenium“. In this post, we discuss two methods to find the elements on a webpage namely findElement and findElements methods.

Let’s see the detailed overview – difference between findElement and findElements methods.

The difference between findElement and findElements methods:

FINDELEMENT() METHOD:

findElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.

Syntax:

FINDELEMENTS() METHOD:

findElements method returns the list of all matching elements. The findElement method throws a NoSuchElementException exception when the element is not available on the page. Whereas, the findElements method returns  an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.

Syntax:

Let’s see a practical example – FindElement and FindElements methods in Selenium WebDriver:

FindElement method:

FindElements method:

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar

3 thoughts on “Difference Between FindElement And FindElements Methods”

  1. List link = driver.findElements(By.xpath(“//*[@id=’rso’]/div/div/div/h3/a”));

    should be like this otherwise it ill show type mismatch issue.

    List link = driver.findElements(By.xpath(“//*[@id=’rso’]/div/div/div/h3/a”));

    • Whats your point Ashish. I didnt get you.

  2. if i want to know
    1. total no. of links present
    2. text of any nth link
    then how to code?

Leave a Comment

API Testing eBook

DOWNLOAD FOR FREE