When do we use findElement and findElements

0 votes

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

Nov 30, 2020 in Selenium by anonymous
• 10,520 points
698 views

1 answer to this question.

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 <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

answered Nov 30, 2020 by Gitika
• 65,910 points

Related Questions In Selenium

0 votes
1 answer

How do we use assert() in Selenium WebDriver?

So, for implementing Assert(), you need to ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,860 views
0 votes
1 answer

How do we use Gecko driver.exe with Selenium?

Recently Selenium launched v3 and if you ...READ MORE

answered Apr 7, 2018 in Selenium by nsv999
• 5,500 points
525 views
+1 vote
2 answers

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

FindElement Command -This method locates for the ...READ MORE

answered Feb 11, 2020 in Selenium by anonymous
8,059 views
0 votes
2 answers

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,500 points
12,712 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
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,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
+1 vote
2 answers

How do I make selenium check gmails quota storage and then execute another task in a new tab depending on the value?

Hi, Xpath.gettext try this if this doesn't work ...READ MORE

answered Oct 20, 2020 in Selenium by Roshni
• 10,520 points
577 views
0 votes
5 answers

How to use JavaScript in selenium to click an Element?

WebElement element = driver.findElement(By.id("id")); JavascriptExe ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
69,357 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP