Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
About the Author
About the Reviewers

Chapter 2. Locators

Locators allow us to find elements on a page that can be used in our tests. In the last chapter, we managed to work against a page that had decent locators. In HTML, it is seen as a good practice to make sure that every element you need to interact with has an ID attribute and a name attribute. Unfortunately, following best practices can be extremely difficult, especially when building HTML dynamically on the server before sending it back to the browser.

In this chapter, we will cover the following topics:

  • Locate elements by ID

  • Locate elements by name

  • Locate elements by link

  • Locate elements by XPath

  • Locate elements by CSS

  • Locate elements by DOM

So, let's get on with it.


Before starting this chapter, we should begin by making sure that we have all the relevant applications installed. While these are not foolproof, they will give us an idea of how to construct the locator for our tests.

The following are the browser add-ons that will help us inspect and locate the web elements...