Locators – Introduction

Locators are the way to tell Selenium with which web element we like to do something (It can be anything, like: clicking, typing, selecting, verifying, etc.).

Selenium provides different ways of locating those web elements; we call this the locating strategy. In Selenium we can locate web elements by CSS, XPath, Name, Id, and even Link text. We have to define the locators our self, so we have full control over it.

The CSS locating strategy is recommended for three reasons:

  1. It’s faster;
  2. It’s more readable;
  3. It’s more used.

It depends on the browser, but in Internet Explorer the XPath locators are 2 (up to 3) times slower than CSS locators. XPath is implemented differently amongst browsers. It requires very low maintenance, because the syntax is readable and understandable. Beside of that, CSS locators are more used in projects, for example by designers or jQuery experts (which is a frequently used JavaScript library).

Before we start working through this chapter we need to make sure that Mozilla Firefox is installed on the machine with the Firebug add-on. If you do not have Mozilla Firefox installed, you will need to download it from http://www.getfirefox.com/ . Once Mozilla Firefox is installed, you can start downloading the Firebug add-on from http://getfirebug.com/ .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.