Finding an element using the findElement method

Finding elements in Selenium WebDriver is done by using the findElement() and findElements() methods provided by the WebDriver and WebElement interface.

The findElement() method returns an instance of a WebElement that is found in the page DOM based on specified locators, also called search criteria. If it does not find an element using the specified search criteria, it will throw the NoSuchElementFound exception.

The findElements() method returns a list of WebElements matching the search criteria. If no elements are found, it returns an empty list.

Find methods take a locator or a query object as an instance of a By class as an argument. Selenium WebDriver provides a By class to support various locator ...

Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.