Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

What is the difference between find elements() and find element()?

Category: Selenium WebDriver

find element(): It finds the first element within the current page using the given “locating mechanism”. It returns a single WebElement. It is the responsibility of developers and testers to make sure that web elements are uniquely identifiable using certain properties such as ID or name.
Syntax: WebElement userid = driver.findElement(By.id(“Id Value”));

findElements() : Using the given “locating mechanism” it will find all the elements within the current page. It 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.
Syntax: List elementName = driver.findElements(By.LocatorStrategy(“LocatorValue”));

Leave a Reply

Your email address will not be published. Required fields are marked *