Element Identifiers - Some basics

An element identifier is needed to get a handle of the specific element on which we want to perform certain action.

It is a way to identify an element. The various options that selenium allows you to use for identifying an element are:

  • By id attribute
  • By name attribute
  • By css class name attribute
  • By css locator of the element
  • By xpath locator of the element

If you look at the page class we wrote, we have used one of these startegies to locate elements that the step had to act upon on.

One thing to note in the current implementation though is, the fact that these element identification startegies are tightly coupled with the method in which it is called.

For example "first name" is found by id in the method where we are entering first name. Now suppose there are other methods in the class that also want to use the first name element. These methods will again try to locate the element with similar or a different location strategy, which is not really needed.

Further this would add to unnecessary duplication and a maintainence overhead. In case the id attribute for first name changes, we will have to update the same at multiple places now.

results matching ""

    No results matching ""