Locating elements for automation

Automation for web and app would mean interacting with different elements of the product and performing different actions on these elements. This would need precisely locating the elements by its properties and interacting with it.

There are different ways to locate elements, to be precise there 8 ways to do it. Locating an element is based on the element attribute. Here is a what an element appears as when viewed in developers tool.

Here is a list of all the possible ways an element can be located:

  1. By ID: This is an efficient way to locate any element, as ID are unique for most of the cases. The value of the ID is used to locate the element.
  2. By Name: The value of attribute name is used to locate an element. Name attribute usually appears on buttons
  3. By Class Name: Class name is a very common attribute used for most of the web elements. The value of the class can be used to locate an element.
  4. By Tag Name: This a different way of identifying an element using its tag, where the tag name is used to locate the element. Usually used to identify headings appearing on a page.
  5. By Link Text: Usually, elements with the tag “a<>” can be located using the actual text on the Link. Links such as ‘Forgot password’, ‘here’ can be located using this.
  6. By Partial Link Text: Very similar to Lint text, where we can use a part of the whole link text to locate the element.
  7. By XPATH:
  8. By CSS:

Detailed and practical usage of each locator has been explained in our next blog.

17, March - 2022

Try it now for Free