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.

Note

Before starting this chapter, we should begin by making sure ...

Get Learning Selenium Testing Tools - Third 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.