Book Image

Selenium Testing Tools Cookbook Second Edition

By : UNMESH GUNDECHA
5 (1)
Book Image

Selenium Testing Tools Cookbook Second Edition

5 (1)
By: UNMESH GUNDECHA

Overview of this book

This book is an incremental guide that will help you learn and use the advanced features of the Selenium toolset including the WebDriver API in various situations to build a reliable test automation. You start off by setting up the test development environment and gain tips on the advanced locater strategy and the effective use of the Selenium WebDriver API. After that, the use of design patterns such as data - driven tests and PageFactory are demonstrated. You will then be familiarised with extending Selenium WebDriver API by implementing custom tasks and setting up your own distributed environment to run tests in parallel for cross-browser testing. Finally, we give you some tips on integrating Selenium WebDriver with other popular tools and testing mobile applications. By the end of this book, you will have learned enough to solve complex testing issues on your own.
Table of Contents (16 chapters)
15
Index

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 strategies. The following table lists various locator strategies supported by Selenium WebDriver:

Strategy

Syntax

Description

By ID

Java: driver.findElement(By.id(<element ID>))

C#: driver.FindElement(By.Id(<elementID>))

Python...