Using Selenium, when do we use findElement(...) and findElements(...)?
Experience Level: Junior
Tags: Quality Assurance (QA)Selenium
Answer
Both methods are used to locate an element on a page. Each of them has slightly different behaviour.
Method findElement(...) finds the element matching the criteria. If no element is found, exception is thrown. If one or more elements are found, the first element is returned.
In contrast, the findElements(...) returns the list of matching elements. If no element is found, empty list is returned. If one or more elements are found, they will be present in the returned list?
Related Selenium job interview questions
How to capture a screenshot using Selenium WebDriver?
Quality Assurance (QA)Selenium MediorCan Selenium handle windows based pop up?
Quality Assurance (QA)Selenium JuniorHow to type text into a textbox using Selenium?
Quality Assurance (QA)Selenium JuniorHow do I launch the browser using Selenium WebDriver?
Quality Assurance (QA)Selenium JuniorWhich is the latest Selenium tool?
Quality Assurance (QA)Selenium Junior