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

0 votes
May 8 in Selenium by Nilaabh
423 views

1 answer to this question.

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
• 13,400 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,090 points
5,589 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,090 points
750 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
997 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
709 views
0 votes
1 answer

What is the difference between getWindowHandle() and getWindowHandles() methods in Selenium WebDriver?

Hey Jennifer, difference between getWindowHandle() and getWindowHandles() ...READ MORE

answered Jun 3 in Selenium by Anvi
• 13,400 points
385 views
0 votes
1 answer