Summary -

In this topic, we described about the below sections -

Danger! Identifier locating strategy is obsolete and not supported by webdriver now.

Identifier was used as a default type earlier and used locating strategies both ID and Name. This strategy first tries to find out first matching ID attribute element. If matching ID element is found, the element uses for testing. If the matching ID attribute element not found, then it tries to find first matching name attribute element. If found, the first matching name attribute element used for testing. Otherwise, test case execution gets failed.

Pros

  • This strategy doesn’t depend on the page structure.
  • Works even if the page structure changes

Cons

  • Easily matches several elements.
  • Only works on the first matched element.

Example

Now, let’s understand the working of ID locator with the help of a simple example. For example, we will launch Firefox and navigate to google.com. Here, we try to locate the search box using identifier Locator.

Identifier

From the above screen shot, the below code specifies locate identifier code –

identifier=q

While running the test, it first searches for the below identifier -

Id=q

Identifier

If "Id=q" found, the first found identifier uses for testing.

If "Id=q" not found, it again searches for the below identifier -

name=q

Identifier

If "name=q" found, the first found identifier uses for testing. If "name=q" not found, then running test case gets failed.