Julia Pottinger
0

Element Locator Strategy - Introduction

August 04, 2020

This is the first blog post in a series on locator strategies.

Locators are very important when doing test automation. Identifying proper locators is one of the most important steps when writing tests and contributes to the building of efficient scripts. It helps to ensure that tests are maintainable, reliable and is less flaky overtime.

What are web elements?

Elements on a webpage are created using HTML(Hyper Text Markup Language). Standard markup language for creating Web pages and describes the structure of a Web page using a series of elements that tell the browser how to display content. An HTML element is defined by a start tag, some content, and an end tag:

<tagname> Element Content </tagname>

<h1> HTML Element Tutorial </h1>
<button> Click Here </button>

There is a diverse range of web elements. For Example:

  • Text box
  • Button
  • Drop Down
  • Hyperlink
  • Check Box
  • Radio Button

Element Locator

An element locator is different from an element. An element is rendered on a webpage while an element locator is an address that uniquely identifies a web element within a webpage. An element locator is also referred to as selector/identifier and finds and returns specific elements and can be found using different strategies.

Locators are used by our tests to perform specific actions on a web page such as clicking on a link or button, getting the text of a header or entering some value into an input field.

Locator Strategies

There are several different locator strategies that can be used to find elements such as:

  • ID
  • Name
  • Class Names
  • CSS
  • XPATH

We will be going through each of these locator strategies in this series.

Proper Locator Strategy

It is very important that we follow proper locator strategy when doing test automation as the application can and will change, and test automation needs to be maintained to test those changes.

It is advised that you use the element selector that is most unlikely to change to make the automation as robust as possible. This is not set in stone but generally you want to adopt this priority order when finding elements.

  • Unique id
  • Unique class
  • Unique attributes

It is also very important that developers when creating web elements follow this as it will greatly improve how friendly an application is for test automation resulting in more reliable and maintainable tests.

Check out the Youtube Tutorial for this blog.


Written by Julia Pottinger who lives and works in Jamaica building useful things. Follow her on Twitter and check out her YouTube Channel

Sign up for Newsletter

Share this blog

© 2022 Julia Pottinger - All Rights Reserved