Placeholder canvas

How to choose locators for automation testing

How to Choose Locators for Automation Testing?

folder_openTest Automation

How to Choose Locators for Automation Testing?

A good locator provides stability for test automation with low maintenance requirements.

But how to choose reliable locators for automation testing?

Let us find out in the following sections.

Criteria for Selecting Good Locators for Test Automation

  • A locator should be small and stays unaffected by modifications in parents.
  • A locator needs to match the desired element. There is no use of locators if it matches other elements during the software testing.
  • A single locator should match unique and specific elements.
  • Multiple locators should match with an equal number of elements but no others.
  • Do not trust changeable information for choosing locators. You need to determine the difference between reliable and non-reliable information carefully.
  • It is crucial because it will help to conduct low-maintenance and stable automation testing.
  • Choose a locator that can pull through its property changes or upgrades.
  • Don’t use elements that depend upon self-generated values like id=tooltip
  • Use locators such as ID, CSS, Xpath, etc
  • Locators should be independent of HTML structure for stability.

How do form locators use attributes such as IDs, Class Names etc

Locators’ formation through the following attributes and path.

Location Description Syntax in Java
ID Recognise the web element applying the ID attribute Driver.findElement (“idvalue”)
Class Name Apply the Class attribute to recognise the web element Driver.findElement (By.className (“classValue”)
CSS Selector CSS used to create style rules in a web page is leveraged to locate the desired web element Driver.findElement (By.cssSelector (“cssValue”)
Tag Name Tag name to locate the web element Driver.findElement (By.tagName (“htmltag”)
XPath Apply XPath to locate the required web element Driver.findElement (By.xpath(“xpathvalue”)
Partial Link Text Use a part of the text in hyperlinks to locate the desired web element Driver.findElement (By.partialLinkText (“PartialTextofLink”)
Link Text Use the texts in hyperlinks to recognise the web element Driver.findElement (By.linkText (“textoflink”)
Name Recognise the web element with the Name attribute Driver.findElement ( (“namevalue”)

How to write dynamic locators vs static locators?

  • Locators are vital components of writing a successful software testing script. Some of these elements are static, and some of them are dynamic. There are different methods to manage both categories of locators.
  • Static locators remain unchanged. Dynamic elements rely on changing aspects.
  • Static objects remain stable. It is easy to manage and choose a preferable selector like XPath. Though XPath is commonly applied, other selectors follow a similar method.
  • Dynamic locators are tricky as they function according to changing properties. It needs to be more stable.
  • You can use algoQA for locator finding to conduct faster & efficient software testing.

How to implement polling methods?

Polling methods in software testing improves the efficiency of application to manage multiple requests. It is highly recommendable for applications that require a long time to process one request.

If one request takes lots of time, there will be a backlog of requests, and the system will not accept new requests.


A client can manage 100 requests at a time. The server takes some minutes to process one request. This situation could cause an inability to accept new customer requests, as there are no free threads.

There should be an asynchronous client instead of a synchronous one to avoid blocking. The polling method is the solution for the asynchronous technique.

How does the polling method work?

  • The client sends an HTTP request to the server
  • The server receives the request and responds with processing of the request still in progress
  • The client conducts a poll method for the server to check if the request has been processed or not
  • The client receives the response if the request has been processed.
  • If processing is still pending, the poll happens again

 Benefits of Choosing algoQA

  • algoQA has a scraper that does the job without manually having to inspect one by one every UI element.
  • It is an artificial intelligence-powered end-to-end automation testing platform.
  • algoQA from AlgoShack facilitates testing beyond UI automation.
  • The automation platform provides a single platform for UI-based functional test automation, load test automation, and API test automation.
  • It is a technology-agnostic platform. It supports multi-lingual scripting, seamless working across ALMs, and multiple reporting formats.
  • You can use algoQA for Web Applications, Mobile Applications, Hybrid Applications, Desktop Applications, Robotic Process Automation, and Embedded Software.
  • Leverages AI and ML for accurate test automation results
  • Auto coding and faster machine-generated scripts
  • algoQA facilitates environment configuration with pre-set browsers, operating systems, and mobile settings.
  • Better methods to manage flaky automation tests
  • Update test automation scripts in seconds
  • You can automatically capture and store locators, in elements repositories.
  • Provides thousands of test cases and executable scripts
  • The enhanced overall productivity of automation tests and minimises go-to-market time.
  • SaaS-based rapid automation with the best return on investment

Learn more about locators and working with algoQA at Contact us for a demo now.

Recent Posts