What is the difference between findElement and findElements in Selenium Webdriver?

0 votes
May 8 in Selenium by Nilaabh
37 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hi Nilaabh, Selenium Webdriver uses findElement and findElements methods to find locators of any web element. Now the difference between them is that the findElement command takes in the By object as the parameter and returns an object of type WebElement

By object in turn can be used with various locator strategies such as ID, Name, Class Name, XPATH etc. This method throws exception NoSuchElementException if there are no elements matching the locator. Following is the syntax of findElement command in Selenium web driver:

WebElement elementName = driver.findElement(By.LocatorStrategy("LocatorValue"));

While, findElements command takes in By object as the parameter and returns a list of web elements. It returns an empty list if there are no elements found using the given locator strategy and locator value. Returns an empty list if there are no web elements matching the locator strategy. Below is the syntax of findElements command:

List<WebElement> elementName = driver.findElements(By.LocatorStrategy("LocatorValue"));
answered May 8 by Anvi
• 5,960 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
3,529 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
75 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
448 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
56 views
0 votes
1 answer

What is POM in Selenium and what it is used for?

Hello Rubina, POM is Page Object Model which ...READ MORE

answered May 12 in Selenium by Anvi
• 5,960 points
18 views
0 votes
1 answer

What are the main functions of Xpath locator in Selenium?

Hi Danish, for handling complex and dynamic ...READ MORE

answered May 9 in Selenium by Anvi
• 5,960 points
12 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.